#include <bits/stdc++.h>
using namespace std;
int nn, mm;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
bool in_range(int i, int j) { return (i >= 0 && i < nn && j >= 0 && j < mm); }
int n, i, a[1000001], ans[1000001], res;
int T[400001];
int query(int v, int tl, int tr, int l, int r) {
  if (l > r) return 0;
  if (tl == l && tr == r) {
    return T[v];
  };
  int tm = (tl + tr) / 2;
  return max(query(2 * v, tl, tm, l, min(tm, r)),
             query(2 * v + 1, tm + 1, tr, max(tm + 1, l), r));
};
void update(int v, int tl, int tr, int pos, int val) {
  if (tl == tr) {
    T[v] = val;
    return;
  };
  int tm = (tl + tr) / 2;
  if (tm >= pos)
    update(2 * v, tl, tm, pos, val);
  else
    update(2 * v + 1, tm + 1, tr, pos, val);
  T[v] = max(T[2 * v], T[2 * v + 1]);
};
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i <= n; i++) {
    ans[a[i]] = query(1, 1, n, 1, a[i] - 1) + 1;
    update(1, 1, n, a[i], ans[a[i]]);
    res = max(res, ans[a[i]]);
  };
  cout << res;
  return 0;
}
