#include <bits/stdc++.h>
using namespace std;
static const int INF = 100000000;
int n;
int a[101010];
int dp[101010];
int main() {
  memset(a, 0, sizeof(a));
  fill(dp, dp + n, INF);
  scanf("%d", &n);
  for (int i = (int)0; i < (int)n; ++i) {
    scanf("%d", &a[i]);
  }
  for (int i = (int)0; i < (int)n; ++i) {
    *lower_bound(dp, dp + n, a[i]) = a[i];
  }
  printf("%d\n", lower_bound(dp, dp + n, INF) - dp);
  return 0;
}
