#include <bits/stdc++.h>
using namespace std;
const int IMAX = ((1 << 30) - 1) * 2 + 1;
const int INF = 100000000;
const double EPS = 1e-10;
const int MAX_N = 100000;
int n, a[MAX_N];
int dp[MAX_N];
int solve() {
  fill(dp, dp + n, INF);
  for (int i = 0; i < n; i++) {
    *lower_bound(dp, dp + n, a[i]) = a[i];
  }
  return lower_bound(dp, dp + n, INF) - dp;
}
int main() {
  cin >> n;
  for (int i = (0); i < (n); i++) cin >> a[i];
  cout << solve() << endl;
}
