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

const int INF = 1LL << 60;

signed main(void){
  
  int n; cin >> n;
  vector<int> dp(101000,INF);
  
  for(int i = 0; i < n; i++){
    int a; cin >> a;
    
    int itr = lower_bound(dp.begin(),dp.end(),a)-dp.begin();
    
    dp[itr] = a;
  }

  for(int i = 101000-1; i >= 0; i--){
    if( dp[i] != INF ){ cout << i+1 << endl; return 0;}
    
  }

  return 0;
} 
