#include <bits/stdc++.h>
using namespace std;
const int MOD(1000000009);
const int INF((1 << 30) - 1);
const int MAXN(100005);
int a[MAXN], na = 0;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    int low = 0, high = na - 1, mid, pos = na;
    while (low <= high) {
      mid = (low + high) / 2;
      if (a[mid] > x)
        pos = mid, high = mid - 1;
      else
        low = mid + 1;
    }
    a[pos] = x;
    if (pos == na) na++;
  }
  printf("%d", na);
}
