#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 20;
int a[M], lis[M], sz;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    int ind = lower_bound(lis, lis + sz, a[i]) - lis;
    lis[ind] = a[i];
    if (ind == sz) sz++;
  }
  cout << sz << "\n";
  return 0;
}
