#include <bits/stdc++.h>
using namespace std;
int tab[100005], z, n, a, i, j;
int* it;
int main() {
  scanf("%d", &n);
  for (j = 0; j <= n; ++j) tab[j] = 2000000001;
  for (j = 0; j < n; ++j) {
    scanf("%d", &a);
    it = lower_bound(tab, tab + n, a);
    *it = a;
  }
  for (j = 0; j <= n; ++j)
    if (tab[j] == 2000000001) break;
  printf("%d\n", j);
  return 0;
}
