#include <bits/stdc++.h>
using namespace std;
const int N = 111111;
int n;
int top;
int a[N];
int main() {
  scanf("%d", &n);
  top = 0;
  for (int i = 0; i != n + 1; i++) a[i] = N;
  for (int i = 0; i != n; i++) {
    int x;
    scanf("%d", &x);
    int w = upper_bound(a + 1, a + n, x) - a;
    top = max(top, w);
    a[w] = x;
  }
  printf("%d\n", top);
  return 0;
}
