#include <bits/stdc++.h>
using namespace std;
int in[100005];
int dp[100005];
int main() {
  int n;
  scanf("%d", &n);
  fill(dp, dp + 100005, 1000000000);
  dp[0] = 0;
  int ret = 0;
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    int s = 0, e = 100005;
    while (e - s > 1) {
      int med = (s + e) / 2;
      if (dp[med] < a)
        s = med;
      else
        e = med;
    }
    dp[s + 1] = a;
    ret = max(ret, s + 1);
  }
  printf("%d\n", ret);
  return 0;
}
