#include <bits/stdc++.h>
int N;
int a[100000];
int dp[100000];
int max(int a, int b) { return a > b ? a : b; }
int l_bound(int x) {
  int l, h, m;
  l = 0;
  int i;
  h = N - 1;
  while (h - l > 1) {
    m = (l + h) / 2;
    if (dp[m] >= x)
      h = m;
    else
      l = m;
  }
  if (dp[l] <= x)
    return h;
  else
    return l;
}
int main() {
  int i, j, k;
  int res = 0;
  scanf("%d", &N);
  for (i = 0; i < N; i++) scanf("%d", &a[i]);
  for (i = 0; i < N; i++) dp[i] = 100000000;
  for (i = 0; i < N; i++) {
    j = l_bound(a[i]);
    dp[j] = a[i];
  }
  i = 0;
  while (dp[i] < 100000000 && i < N) i++;
  printf("%d\n", i);
  return 0;
}
