#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 5;
int a[M];
int32_t main() {
  int n;
  cin >> n;
  memset(a, 31, sizeof a);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a[lower_bound(a, a + M, x) - a] = x;
  }
  return cout << int(lower_bound(a, a + M, M) - a) << endl, 0;
}
