#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vt;
int a[110000];
int n;
void solve() {
  vt v;
  vt::iterator it;
  for (int i = 0; i < n; i++) {
    it = upper_bound(v.begin(), v.end(), a[i]);
    if (it == v.end())
      v.push_back(a[i]);
    else
      *it = a[i];
  }
  cout << v.size() << endl;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  solve();
  return 0;
}
