#include <bits/stdc++.h>
using namespace std;
int n;
int a[100005];
int L[100005];
int len = 1;
int main() {
  cin >> n;
  for (int i = 0; i < (n); i++) cin >> a[i];
  for (int i = 0; i < (n); i++)
    if (i) {
      if (L[len - 1] < a[i]) {
        L[len] = a[i];
        len++;
      } else {
        int pos = lower_bound(L, L + len, a[i]) - L;
        L[pos] = a[i];
      }
    }
  cout << len - 1 << endl;
  return 0;
}
