#include <bits/stdc++.h>
using namespace std;
int scan(int *buf_tar) {
  char buf_c = 0;
  bool is_rev = 0;
  while (buf_c != '-' && (buf_c < '0' || buf_c > '9')) {
    buf_c = getchar();
    if (buf_c == EOF) return EOF;
  }
  if (buf_c == '-') is_rev = 1, buf_c = getchar();
  *buf_tar = 0;
  while (buf_c >= '0' && buf_c <= '9') {
    *buf_tar *= 10;
    *buf_tar += buf_c - '0';
    buf_c = getchar();
  }
  if (is_rev) *buf_tar = -*buf_tar;
  return 0;
}
int scan(long long *buf_tar) {
  char buf_c = 0;
  bool is_rev = 0;
  while (buf_c != '-' && (buf_c < '0' || buf_c > '9')) {
    buf_c = getchar();
    if (buf_c == EOF) return EOF;
  }
  if (buf_c == '-') is_rev = 1, buf_c = getchar();
  *buf_tar = 0;
  while (buf_c >= '0' && buf_c <= '9') {
    *buf_tar *= 10;
    *buf_tar += buf_c - '0';
    buf_c = getchar();
  }
  if (is_rev) *buf_tar = -*buf_tar;
  return 0;
}
int n;
int num[100010];
int f[100010], mi[100010];
inline int bsearch(const int, const int, const int);
int main() {
  int temp;
  scan(&n);
  for (int i = 1; i <= n; i++) {
    scan(&num[i]);
    mi[i] = 0x7fffffff;
  }
  f[1] = 1;
  mi[1] = num[1];
  for (int i = 2; i <= n; i++) {
    temp = bsearch(1, i - 1, num[i]);
    mi[temp + 1] = num[i];
    f[i] = temp + 1;
  }
  for (int i = 1; i <= n + 1; i++) f[i] = max(f[i], f[i - 1]);
  printf("%d", f[n]);
  return 0;
}
inline int bsearch(const int l, const int r, const int s) {
  if (l == r) {
    if (mi[l] < s) return l;
    return l - 1;
  }
  int mid = (l + r) >> 1;
  if (mi[mid] < s && mi[mid + 1] > s) return mid;
  if (mi[mid] >= s) return bsearch(l, mid, s);
  return bsearch(mid + 1, r, s);
}
