#include <bits/stdc++.h>
int divide_ffb(int a[], int l, int key);
int main() {
  int n, i, a, b[100000], l, pos, j;
  while (~scanf("%d", &n)) {
    if (n == 0) {
      printf("0\n");
      continue;
    }
    scanf("%d", &a);
    b[0] = a;
    l = 1;
    for (i = 1; i < n; i++) {
      scanf("%d", &a);
      pos = divide_ffb(b, l, a);
      b[pos] = a;
      if (pos == l) l++;
    }
    printf("%d\n", l);
  }
  return 0;
}
int divide_ffb(int b[], int l, int key) {
  int mid, s = 0, e = l - 1;
  if (key > b[l - 1]) return l;
  while (s < e) {
    mid = s + (e - s) / 2;
    if (b[mid] <= key)
      s = mid + 1;
    else
      e = mid;
  }
  return s;
}
