#include <bits/stdc++.h>
using namespace std;
int n;
int len = 0;
int L[100001];
vector<int> A;
void longetIncreasingSubsequence() {
  fill(L, L + n + 1, -1);
  for (int i = 0; i < n; ++i) {
    if (L[len - 1] <= A[i]) {
      L[len++] = A[i];
    } else {
      int *j = lower_bound(L, L + len, A[i]);
      *j = A[i];
    }
  }
}
int main() {
  scanf("%d", &n);
  int a;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a);
    A.push_back(a);
  }
  longetIncreasingSubsequence();
  printf("%d\n", len);
}
