#include<iostream>
#include<algorithm>
using namespace std;
#define int64 long long
#define INF 1000000001

int main(){

  int n;
  cin >> n;
  
  int64 a[n+1];
  int dp[n+1];
  fill(dp,dp+n,INF);
  for(int i = 0;i < n;i++) cin >> a[i];
  
  for(int i = 0;i < n;i++){
    *lower_bound(dp,dp+n,a[i]) = a[i];
  }

  cout << lower_bound(dp,dp+n,INF)-dp << endl;
  return (0);
}
  