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