#include <bits/stdc++.h>
using namespace std;
const int modulo = 222222;
const int maxN = 888888;
int a[maxN], rsq[maxN];
void replace(int i, int x) {
  i += modulo - 1;
  rsq[i] = max(rsq[i], x);
  i /= 2;
  while (i > 0) {
    rsq[i] = max(rsq[i + i], rsq[i + i + 1]);
    i /= 2;
  }
}
int getMax(int l, int r) {
  int i = l + modulo - 1, j = r + modulo - 1, ans = 0;
  while (i <= j) {
    if (i % 2) ans = max(ans, rsq[i]);
    if ((j + 1) % 2) ans = max(ans, rsq[j]);
    i = (i + 1) / 2;
    j = (j - 1) / 2;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) {
    replace(i, 0);
  }
  for (int i = 1; i <= n; ++i) {
    int x = a[i], y = getMax(1, x - 1);
    replace(x, y + 1);
  }
  cout << getMax(1, n) << endl;
  return 0;
}
