#include <bits/stdc++.h>
using namespace std;
vector<int> dp;
void ok(int curr, int val) {
  curr /= 2;
  while (curr > 0) {
    dp[curr] = max(dp[2 * curr], dp[2 * curr + 1]);
    curr /= 2;
  }
}
int query(int a, int b, int curr, int l, int r) {
  if (a > r || b < l) {
    return 0;
  }
  if (a <= l && b >= r) {
    return dp[curr];
  }
  int h = (l + r) / 2;
  return max(query(a, b, 2 * curr, l, h), query(a, b, 2 * curr + 1, h + 1, r));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, a;
  cin >> n;
  int t = pow(2, ceil(double(log2(n))));
  dp.resize(2 * t, 0);
  for (int i = 0; i < n; i += 1) {
    cin >> a;
    if (a > 1) {
      dp[t + a - 1] = 1 + query(t, t + a - 2, 1, t, 2 * t - 1);
      ok(t + a - 1, dp[t + a - 1]);
    } else {
      dp[t + a - 1] = 1;
    }
  }
  cout << dp[1];
}
