#include <bits/stdc++.h>
using namespace std;
int solve(int n, vector<int>& a);
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  cout << solve(n, a) << endl;
  return 0;
}
int solve(int n, vector<int>& a) {
  vector<vector<int> > b(n, vector<int>(n));
  for (int i = 0; i < n; ++i) {
    b[i][i] = 1;
  }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n - i; ++j) {
      int k = i + j;
      int maximum = 1;
      for (int l = j + 1; l <= k; ++l)
        if (a[l] > a[j]) maximum = max(maximum, b[l][k] + 1);
      b[j][k] = maximum;
    }
  int maximum = 0;
  for (int i = 0; i < n; ++i) maximum = max(maximum, b[i][n - 1]);
  return maximum;
}
