#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair pii; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define all(a) (a).begin(),(a).end() #define pb emplace_back #define INF (1e9+1) int main(){ int n; cin>>n; vector v(n); rep(i,n)cin>>v[i]; vector dp(n,INF); rep(i,n){ *upper_bound(all(dp),v[i]) = v[i]; if(v[i]==n)break; } int l = lower_bound(all(dp),INF) - dp.begin(); cout<