#include <bits/stdc++.h>
using namespace std;
int a[100001], m[100002], p[100002];
int main() {
  int n, i, j, k, l = 0, lo, hi, mid, f;
  scanf("%d", &n);
  for (i = 0; i < n; ++i) scanf("%d", a + i);
  for (i = 0; i < n; ++i) {
    lo = 1;
    hi = l;
    while (lo <= hi) {
      mid = ceil((lo + hi) / 2);
      if (a[m[mid]] < a[i])
        lo = mid + 1;
      else
        hi = mid - 1;
    }
    f = lo;
    p[i] = m[f - 1];
    m[f] = i;
    if (f > l) l = f;
  }
  printf("%d", l);
  return 0;
}
