#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  int a[100000];
  int length = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  int A[100000];
  for (int i = 0; i < n; i++) {
    A[i] = 1000000000;
  }
  for (int i = 0; i < n; i++) {
    int* t = upper_bound(A, A + length, a[i]);
    *t = a[i];
    if (A[length] != 1000000000) {
      length++;
    }
  }
  printf("%d\n", length);
}
