#include <bits/stdc++.h>
using namespace std;
int a[100100];
int d[100100];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i <= n; i++) {
    d[i] = 100100;
  }
  d[0] = 0;
  for (int i = 0; i < n; i++) {
    int l = 0;
    int r = n - 1;
    while (l < r) {
      int m = (l + r + 1) / 2;
      if (d[m] > a[i]) {
        r = m - 1;
      } else {
        l = m;
      }
    }
    d[r + 1] = a[i];
  }
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    if (d[i] < 100100) {
      ans = i;
    }
  }
  printf("%d\n", ans);
  return 0;
}
