#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; ++i) cin >> a[i];
  vector<int> lis;
  for (int i = 0; i < n; ++i) {
    vector<int>::iterator it = lower_bound(lis.begin(), lis.end(), a[i]);
    if (it == lis.end())
      lis.push_back(a[i]);
    else
      *it = a[i];
  }
  cout << (int)lis.size();
  return 0;
}
