#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 10;
int n, a[maxN], len, t[maxN];
int main() {
  cin >> n;
  t[0] = maxN;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    int x = lower_bound(t, t + len, a[i]) - t;
    t[x] = a[i];
    if (x == len) t[++len] = maxN;
  }
  cout << len;
  return 0;
}
