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