#include <bits/stdc++.h>
using namespace std;
int a[200000], map[200000];
int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < 150000; i++) map[i] = 150000;
  for (int i = 0; i < n; i++) {
    int *p = lower_bound(map, map + 200000, a[i]);
    *p = min(*p, a[i]);
  }
  printf("%d\n", lower_bound(map, map + 200000, 150000) - map);
  return 0;
}
