#include <bits/stdc++.h>
using namespace std;
int a[100009], g[100009], d[100009];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) g[i] = 0x7fffffff;
  for (int i = 0; i < n; i++) {
    int k = lower_bound(g + 1, g + n + 1, a[i]) - g;
    d[i] = k;
    g[k] = a[i];
  }
  int ans = 0;
  for (int i = 0; i < n; i++) ans = max(ans, d[i]);
  printf("%d", ans);
}
