#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ab;
  cin >> n;
  vector<int> a, b;
  vector<vector<int> > maxL(n + 1, vector<int>(n + 1));
  for (int variable = 0; variable < n; ++variable) {
    cin >> ab;
    a.push_back(ab);
    b.push_back(ab);
  }
  sort(b.begin(), b.end());
  for (int i = 0; i <= n; ++i)
    for (int j = 0; j <= n; ++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][n] << endl;
}
