#include <bits/stdc++.h>
using namespace std;
int N;
int INF = 1e9 + 1;
int dp[100001];
int a[100001];
int main(void) {
  cin >> N;
  fill(dp, dp + N, INF);
  for (int i = 0; i < N; ++i) {
    *lower_bound(dp, dp + N, a[i]) = a[i];
  }
  cout << lower_bound(dp, dp + N, INF) - dp << endl;
  return 0;
}
