#include <bits/stdc++.h>
using namespace std;
const int num = 100001;
int a[num];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  set<int> s;
  for (int i = 0; i < n; i++) {
    set<int>::iterator it = lower_bound(s.begin(), s.end(), a[i]);
    if (it != s.end()) {
      s.erase(*it);
    }
    s.insert(a[i]);
  }
  cout << s.size() - 1 << endl;
  return 0;
}
