#include <bits/stdc++.h>
using namespace std;
int getCeil(int *arr, int s, int e, int x) {
  while (s <= e) {
    if (s == e) return s;
    if (s + 1 == e) {
      if (arr[s] > x)
        return s;
      else
        return e;
    }
    int mid = (s + e) / 2;
    if (arr[mid] > x && arr[mid - 1] <= x)
      return mid;
    else if (arr[mid] > x && arr[mid - 1] > x)
      e = mid - 1;
    else if (arr[mid] < x)
      s = mid + 1;
  }
}
int main() {
  int n;
  scanf("%d", &n);
  int arr[n];
  for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
  int seq[n];
  seq[0] = arr[0];
  int curLen = 1;
  for (int i = 1; i < n; i++) {
    if (arr[i] < seq[0])
      seq[0] = arr[i];
    else if (arr[i] >= seq[curLen - 1])
      seq[curLen++] = arr[i];
    else
      seq[getCeil(seq, 0, curLen - 1, arr[i])] = arr[i];
  }
  printf("%d\n", curLen);
  return 0;
}
