#include <bits/stdc++.h>
using namespace std;
pair<long long int, int> a[100000];
vector<pair<long long int, int>> buf;
int n, dp[100001], ans;
struct stl_sort_functor_cmp {
  bool operator()(const pair<int, long long int>& a,
                  const pair<int, long long int>& b) const {
    return b.first > a.first;
  }
};
int main() {
  scanf("%d", &n);
  for (int i = 0; n > i; i++) {
    a[i].second = i;
    scanf("%lld", &a[i].first);
  }
  for (int i = 0; n > i; i++) {
    buf.insert(lower_bound(buf.begin(), buf.end(), a[i]), a[i]);
    for (int j = 0; i > j; j++) {
      if (buf[j].first >= a[i].first) break;
      if (dp[buf[j].second] == ans) {
        dp[i] = ans + 1;
        break;
      }
      dp[i] = (((dp[i]) > (dp[buf[j].second] + 1)) ? (dp[i])
                                                   : (dp[buf[j].second] + 1));
    }
    if (!dp[i]) dp[i] = 1;
    ans = (((ans) > (dp[i])) ? (ans) : (dp[i]));
  }
  printf("%d\n", ans);
}
