#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, chk = 0, ans = 0;
  scanf("%d", &n);
  int dp[n];
  fill(dp, dp + n, n);
  vector<int> l(n);
  for (auto& e : l) {
    scanf("%d", &e);
  }
  for (int i = 0; i < n; i++) {
    *lower_bound(dp, dp + n, l[i]) = l[i];
  }
  printf("%d\n", lower_bound(dp, dp + n, n) - dp);
  return 0;
}
