#include<iostream>
#include<algorithm>
using namespace std;
#define MAX 100000
#define INF 1 << 30

int n, dp[MAX + 1], a[MAX + 1], length = 0;

int main(){
  cin >> n;
  int val;
  dp[0] = -1;
  for ( int i = 0; i < n; i++){
    cin >> val;
    if ( dp[length] < val){
      dp[++length] = val;
    } else {
      int valMaxLength = lower_bound(dp, dp+length, val) - dp;
      dp[valMaxLength] = val;
    }
  }

  cout << length << endl;

  return 0;
}
