#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int a[MAXN];
vector<int> v;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    int l = lower_bound(v.begin(), v.end(), a[i]) - v.begin();
    if (l == v.size())
      v.push_back(a[i]);
    else
      v[l] = a[i];
  }
  cout << v.size() << endl;
  return 0;
}
