#include <bits/stdc++.h>
const int MAX_N = 100000, INF = std::numeric_limits<int>::max() >> 2;
int n, a[MAX_N];
int dp[MAX_N + 1];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (n); ++i) scanf("%d", a + i);
  std::fill(dp, dp + n + 1, INF);
  for (int i = 0; i < (n); ++i) *std::lower_bound(dp, dp + n + 1, a[i]) = a[i];
  printf("%d\n", std::lower_bound(dp, dp + n + 1, INF) - dp);
  return 0;
}
