#include <bits/stdc++.h>
using namespace std;
int A[100001];
vector<int> L;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &A[i]);
  L.push_back(A[0]);
  vector<int>::iterator pos;
  for (int i = 1; i < n; i++) {
    pos = upper_bound(L.begin(), L.end(), A[i]);
    if (pos == L.end()) {
      L.push_back(A[i]);
    } else {
      int idx = pos - L.begin();
      L[idx] = A[i];
    }
  }
  printf("%d", L.size());
  return 0;
}
