#include <iostream>
#include <algorithm>
using namespace std;

int main(){

  int n;
  int dp[100001] = {};
  int a[100001] = {};

  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  int len = 1;
  dp[0] = a[0];
  for(int i = 1; i < n; i++){
    if(dp[len-1] < a[i]){
      dp[len++] = a[i];
    }else{
      *lower_bound(dp, dp+len, a[i]) = a[i];
    }
  }
  cout << len << endl;
  return 0;
}
