#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
const double pi = 2 * asin(1.0);
int n;
int m;
int x[100002];
int y[100002];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &x[i]);
  y[0] = 0;
  for (int i = 1; i <= n + 1; i++) y[i] = n + 1;
  for (int i = 0; i < n; i++) {
    int l = 0, r = i + 1;
    while (r - l > 1) {
      int s = (l + r) / 2;
      if (y[s] <= x[i])
        l = s;
      else
        r = s;
    }
    y[l + 1] = min(y[l + 1], x[i]);
  }
  int ans = 0;
  while (y[ans + 1] <= n) ans++;
  printf("%d\n", ans);
  return 0;
}
