#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll a[114514],b[114514];
int main(){
	ll n,inf=1e15;
	cin>>n;
	b[n+1]=inf;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		b[i]=-inf;
	}
	ll ans=1;
	b[1]=a[1];
	b[0]=inf;
	b[n+1]=-inf;
	for(int i=2;i<=n;i++){
		if(b[ans]>=a[i]){
			ans++;
			b[ans]=a[i];
		}else{
			ll ng=0,ok=n+1;
			while(ok-ng>1){
				ll mid=(ok+ng)/2;
				if(b[mid]>=a[i])ng=mid;
				else ok=mid;
			}
			b[ok]=a[i];
		}
	}
	//for(int i=0;i<=5;i++)cout<<b[i]<<' ';
	cout<<ans;
	return 0;
}

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1000000007;

#define vec              vector<int>
#define vecll            vector<ll>
#define vecd             vector<double>
#define vecst            vector<string>
#define vecb             vector<bool>
#define v2(v,n,m,init)   vector<vector<int>>  v(n, vector<int>(m, init))
#define vb2(v,n,m,init)  vector<vector<bool>> v(n, vector<bool>(m, init))
#define vll2(v,n,m,init) vector<vector<ll>>   v(n, vector<ll>(m, init))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
template <typename T>
bool chmax(T &a, const T& b){if(a<b){a=b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a>b){a=b; return true;} return false;}
//----------------------------------------------------------------

int main(void) {
  int n;
  cin >> n;
  arrll(a,n);
  rep(i,n){
    a[i] = 1000000000-a[i];
  }
  ll INF = 1e18;
  vecll dp(n, INF);

  rep(i,n){
    auto tmp = upper_bound(all(dp), a[i]);
    *tmp = a[i];
  }

  auto ans = lower_bound(all(dp), ll(1e18)-1);
  prt(ans-dp.begin());
}
