#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9, MOD = 1e9 + 7,
          around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};
const long double PI = abs(acos(-1));
int n, a, li[100010];
int main() {
  cin >> n >> li[0];
  int l = 1;
  for (int i = (1); i < (n); i++) {
    cin >> a;
    if (li[l - 1] < a)
      li[l++] = a;
    else
      *upper_bound(li, li + l, a) = a;
  }
  cout << l << endl;
  return 0;
}
