#include <bits/stdc++.h>
#pragma comment(linker, "/stack:64000000,64000000")
using namespace std;
int n;
int a[100002];
void start();
int main() {
  start();
  return 0;
}
void start() {
  for (int i = 1; i < 100002; ++i) {
    a[i] = 1000000;
  }
  int max_ind = 1;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int z;
    scanf("%d", &z);
    int ind = lower_bound(a + 1, a + 100002, z) - a;
    a[ind] = z;
    max_ind = max(ind, max_ind);
  }
  printf("%d", max_ind);
  return;
}
