#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to, cost;
  edge(int t, int c) : to(t), cost(c) {}
};
const int inf = 100100100;
const long long linf = (long long)1e18;
const int mod = (int)(1e9 + 7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int a[n], dp[n];
  for (int(i) = 0; (i) < (int)(n); (i)++) cin >> a[i];
  fill(dp, dp + n, inf);
  for (int(i) = 0; (i) < (int)(n); (i)++) {
    *lower_bound(dp, dp + n, a[i]) = a[i];
  }
  cout << lower_bound(dp, dp + n, inf) - dp << "\n";
}
