#include <bits/stdc++.h>
using namespace std;
int n;
int a[100514], top;
void truli() {
  scanf("%d", &n);
  int x;
  top = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    if (a[top - 1] < x) {
      a[top++] = x;
      continue;
    }
    int t = -1;
    for (int bt = 20; bt >= 0; bt--) {
      if (t + (1 << bt) < top && a[t + (1 << bt)] < x) t += (1 << bt);
    }
    a[t + 1] = x;
  }
  printf("%d\n", top);
}
int main() {
  truli();
  return 0;
}
