#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) {
    int pos = (lower_bound(lis.begin(), lis.end(), a[i]) - lis.begin());
    if (pos == lis.size())
      lis.push_back(a[i]);
    else
      lis[pos] = a[i];
  }
  cout << (int)lis.size();
  return 0;
}
