#include <bits/stdc++.h>
using namespace std;
int binarySearch(vector<int> &num, vector<int> &store, int s, int e, int x) {
  if (s > e) return 0;
  int mid = (s + e) / 2;
  if (num[store[mid]] <= x)
    return max(mid, binarySearch(num, store, mid + 1, e, x));
  return binarySearch(num, store, s, mid - 1, x);
}
int main() {
  vector<int> num(100005), store(100005);
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &num[i]);
  int L = 1;
  store[1] = 0;
  for (int i = 1; i < n; i++) {
    int len = binarySearch(num, store, 1, L, num[i]);
    len++;
    if (len > L || num[i] < num[store[len]]) store[len] = i;
    L = max(L, len);
  }
  printf("%d\n", L);
  return 0;
}
