#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 100010;

int main() {
  int dp[MAX_N];
  int n, i, a, length;

  scanf("%d",&n);
  scanf("%d",&dp[0]);
  length = 1;

  for (i = 1; i < n; ++i) {
    scanf("%d",&a);
    if (a > dp[length - 1]) {
      dp[length] = a;
      ++length;
    } else {
      *(lower_bound(dp,dp + length, a)) = a;
    }
  }

  cout << length << endl;

  return 0;
}
