#include <bits/stdc++.h>
using namespace std;
const int nm = 100002;
int n, m;
int a[nm];
int b[nm], startof[nm];
void nhap() {
  scanf("%d", &n);
  int i;
  for (i = 1; i <= n; ++i) scanf("%d", &a[i]);
}
int find(int i) {
  int l, r, mid, kq;
  l = 0;
  r = m;
  do {
    mid = (l + r) / 2;
    if (a[startof[mid]] > a[i]) {
      kq = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  } while (l <= r);
  return (startof[kq]);
}
void xuli() {
  b[0] = 0;
  b[n] = 1;
  startof[1] = n;
  startof[0] = n + 1;
  a[n + 1] = n + 1;
  m = 1;
  int i, j;
  for (i = n - 1; i >= 1; --i) {
    j = find(i);
    b[i] = b[j] + 1;
    if (b[i] > m) {
      m = b[i];
      startof[m] = i;
    } else {
      if (a[i] > a[startof[b[i]]]) startof[b[i]] = i;
    }
  }
  printf("%d", m);
}
int main() {
  nhap();
  xuli();
}
