#include <bits/stdc++.h>
using namespace std;
int n, l[100000], dp[100000], r = 0;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &l[i]), dp[i] = INT_MAX;
  for (int i = 0; i < n; i++) *lower_bound(dp, dp + n, l[i]) = l[i];
  printf("%d\n", lower_bound(dp, dp + n, INT_MAX) - dp);
  return 0;
}
