#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int judge(vector<int> b, int ab)
{
	for (int j = 0; j < b.size(); ++j) {
		if (b[j] ==ab) {
			return 1;
			break;
		}
	}
	return 0;
}
int main()
{
	int n, ab;
	cin >> n;
	vector<int> a, b;
	for (int variable = 0; variable < n; ++variable) {
		cin >> ab;
		a.push_back(ab);
		if (judge(b, ab) == 0) {
			b.push_back(ab);
		}
	}
	vector< vector<int> > maxL(n+1,vector<int>(b.size()+1);
	sort(b.begin(), b.end());
	for(int i=0;i<=n;++i)
		for (int j = 0; j <= b.size(); ++j) {
			if (i == 0 || j == 0) maxL[i][j] = 0;
			else if (a[i - 1] == b[j - 1]) maxL[i][j] = maxL[i - 1][j - 1] + 1;
			else maxL[i][j] = max(maxL[i - 1][j], maxL[i][j - 1]);
		}
	cout << maxL[n][b.size()] << endl;
}