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

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

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;   
    });

    std::vector<int> best(size);
    for (int i{}; i < size; i++)
    {
        Line& line = lines[i];
        best[i] = line.weight;
        
        for (int j{}; j < i; j++)            
            if (lines[j].end < line.start)
                best[i] = std::max(best[i], best[j] + line.weight);
    }
   
    std::ofstream fout{"output.txt"};
    fout << *std::max_element(best.begin(), best.end());
    fout.close();
    
    return 0;
}