#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>

struct Line
{
    int start{};
    int end{};
    int weight{};
};

enum operation {TAKE, DROP};

int optimize(operation op, std::vector<Line>::iterator it, std::vector<Line>::iterator end)
{
    int weight{op == TAKE ? it->weight : 0};
    int line_end{it->end};
    
    if (op == DROP) ++it;
    else while ( ++it != end)
            if (it->start > line_end) break;

    if (it == end) return weight;
    
    return weight + std::max(optimize(TAKE, it, end),
                             optimize(DROP, it, end));
}

static const int size = 100;

int main()
{
    std::ifstream fin{"input.txt"};
    
    int N;
    fin >> N;
    
    std::vector<Line> lines(size);
    
    for (int i{}; i < N; i++)
    {
        int num;
        fin >> num;
        Line& line = lines[num - 1];
        
        if (line.start == 0)
            line.start = i;
        line.end = i;
        line.weight++;
    }
    
    fin.close();
    
    std::sort(lines.begin(), lines.end(), [](const Line& a, const Line& b) {
        return b.start > a.start;   
    });

    int result{std::max(optimize(TAKE, lines.begin(), lines.end()),
                        optimize(DROP, lines.begin(), lines.end()))
              };
   
    std::ofstream fout{"output.txt"};
    fout << result;
    fout.close();
    
    return 0;
}