#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

ll n;
ll a[100010];
ll dp[100010];

int main(){
    cin.tie(0); ios::sync_with_stdio(0);
    cin >> n;
    REP(i,n) cin >> a[i];
    REP(i,n) dp[i] = INF;
    REP(i,n) *lower_bound(dp,dp+n,a[i]) = a[i];
    cout << lower_bound(dp,dp+n,INF) - dp << "\n";
    return 0;
}
