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