#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
#define INF 10000000000
#define MAX_N 100000
int main(){
  ll n,a;
  vector<ll> dp(MAX_N+1);
  fill(dp.begin(),dp.end(),INF);
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a;
    *lower_bound(dp.begin(),dp.end(),a) = a;
  }
  cout << distance(dp.begin(),lower_bound(dp.begin(),dp.end(),INF) ) <<endl;
}

