#include <bits/stdc++.h>
using namespace std;
int len;
int s[100005];
int dpi[100005];
int dp[100005];
int last[100005];
int ans[100005];
int main() {
  scanf("%d", &len);
  for (int i = 0; i < len; i++) scanf("%d", &s[i]);
  int max = 0;
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i < len; i++) {
    int k = lower_bound(dp, dp + max, s[i]) - dp;
    if (k == max) {
      dp[max] = s[i];
      dpi[max] = i;
      last[i] = dpi[max - 1];
      max++;
    } else {
      dp[k] = s[i];
      dpi[k] = i;
      last[i] = dpi[k - 1];
    }
  }
  printf("%d\n", max);
  return 0;
}
