#include <bits/stdc++.h>
using namespace std;
const int N = 100015;
int C[N], n;
int main() {
  while (~scanf("%d", &n)) {
    int cnt = 0, x, p;
    for (int i = 0; i < n; i++) {
      scanf("%d", &x);
      if (!cnt || x > C[cnt - 1])
        C[cnt++] = x;
      else {
        p = upper_bound(C, C + cnt, x) - C;
        C[p] = x;
      }
    }
    printf("%d\n", cnt);
  }
  return 0;
}
