#include <bits/stdc++.h>
using namespace std;
int N, L;
int vals[100001];
int m[100000];
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &vals[i]);
    m[i] = 100000;
  }
  vals[100000] = 1 << 30;
  L = 0;
  for (int i = 0; i < N; i++) {
    int lb = 0, ub = L;
    while (ub - lb > 1) {
      int mid = (ub + lb) / 2;
      if (vals[m[mid]] < vals[i])
        lb = mid;
      else
        ub = mid - 1;
    }
    int j = 0;
    for (int t = lb; t <= ub; t++)
      if (vals[m[t]] < vals[i]) j = t;
    if (j == L || vals[i] < vals[m[j + 1]]) {
      m[j + 1] = i;
      L = max(L, j + 1);
    }
  }
  printf("%d\n", L);
  return 0;
}
