#include <bits/stdc++.h>
using namespace std;
const int MX = 1e6 + 5;
const long long INF = 1e18 + 7;
const long long MOD = 1e9 + 7;
int n, res, pre[MX], lay[MX];
long long t[MX];
int BS(int pocz, int konc, long long x) {
  if (konc - pocz <= 5) {
    for (int i = konc; i >= pocz; --i)
      if (t[lay[i]] >= x) return i;
  }
  int sr = (pocz + konc) / 2;
  if (t[lay[sr]] >= x)
    return BS(sr, konc, x);
  else
    return BS(pocz, sr - 1, x);
}
int main() {
  scanf("%d", &n);
  for (int i = (1); i <= (n); ++i) {
    cin >> t[i];
    t[i] = (long long)1e18 - t[i];
  }
  lay[0] = 0;
  t[0] = INF;
  pre[0] = -1;
  for (int i = (1); i <= (n); ++i) {
    int pos = BS(0, res, t[i]);
    pre[i] = lay[pos];
    lay[pos + 1] = i;
    res = max(res, pos + 1);
  }
  printf("%d\n", res);
  vector<int> r;
  int akt = lay[res];
  while (akt != 0) {
    r.push_back(akt);
    akt = pre[akt];
  }
  return 0;
}
