#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30, Array = 0x1e6;
int main() {
  int n;
  int seq[Array], dp[Array];
  scanf("%d", &n);
  fill(dp, dp + n, INF);
  for (int i = 0; i < n; i++) scanf("%d", &seq[i]);
  for (int i = 0; i < n; i++) *lower_bound(dp, dp + n, seq[i]) = seq[i];
  cout << lower_bound(dp, dp + n, INF) - dp << endl;
  return 0;
}
