#include <bits/stdc++.h>
using namespace std;
int n, a[100010], b[100010], ans = 0;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 1; i <= n; ++i) {
    int L = 1, R = ans, M;
    while (L <= R) {
      M = (L + R) >> 1;
      if (a[i] < b[M])
        R = M - 1;
      else
        L = M + 1;
    }
    b[L] = a[i];
    if (L > ans) ans = L;
  }
  printf("%d\n", ans);
  return 0;
}
