#include <bits/stdc++.h>
using namespace std;
const int INF = 1e5 + 100;
int main() {
  int n;
  cin >> n;
  vector<int> V(n);
  for (int &v : V) cin >> v;
  vector<int> D(n, INF);
  for (int v : V) *lower_bound(D.begin(), D.end(), v) = v;
  cout << upper_bound(D.begin(), D.end(), INF - 1) - D.begin() << endl;
}
