#include <bits/stdc++.h>
using namespace std;
int dp[1000000], N, a[1000000];
int main() {
  cin >> N;
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    if (cnt == 0) {
      dp[cnt] = a[i];
      cnt++;
    } else {
      if (dp[cnt - 1] <= a[i]) {
        dp[cnt] = a[i];
        cnt++;
      } else {
        int squirrel = lower_bound(dp, dp + cnt, a[i]) - dp;
        dp[squirrel] = a[i];
      }
    }
  }
  cout << cnt << endl;
  return 0;
}
