#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 1e6 + 10;
int n, m;
int a[N], b[N];
int LIS() {
  int len = 1;
  b[1] = a[1];
  for (int i = 2; i <= n; ++i) {
    if (a[i] > b[len])
      b[++len] = a[i];
    else {
      int j = lower_bound(b + 1, b + 1 + len, a[i]) - b;
      b[j] = a[i];
    }
  }
  return len;
}
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  cout << LIS() << endl;
  return 0;
}
