#include <bits/stdc++.h>
using namespace std;
int a[100005];
int b[100005];
int main() {
  int n;
  scanf("%d", &n);
  int i;
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    b[i] = 999999999;
  }
  int tot = 0;
  for (i = 0; i < n; i++) {
    int now = lower_bound(b, b + tot, a[i]) - b;
    if (now == tot) tot++;
    b[now] = min(b[now], a[i]);
  }
  cout << tot << endl;
  return 0;
}
