#include <bits/stdc++.h>
int inp[100003], m[100003];
int main() {
  int n, i, l, lo, hi, mid;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &inp[i]);
  l = 0;
  for (i = 0; i < n; i++) {
    lo = 0;
    hi = l;
    while (lo < hi) {
      mid = (lo + hi + 1) / 2;
      if (m[mid] < inp[i])
        lo = mid;
      else
        hi = mid - 1;
    }
    if (lo == l) {
      l = lo + 1;
      m[l] = inp[i];
    } else if (inp[i] < m[lo + 1])
      m[lo + 1] = inp[i];
  }
  printf("%d\n", l);
  return 0;
}
