#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    scanf("%d", &n);
    int a[n+1];
    for(int i = 0; i < n; i++) scanf("%d", &a[i]);
    vector<int> dp;
    dp.push_back(a[0]);
    for(int i = 1; i <= n-1; i++){
        if(a[i] > dp[dp.size()-1]){
            dp.push_back(a[i]);
        }
        else{
            *lower_bound(dp.begin(), dp.end(), a[i]) = a[i];
        }
    }
    printf("%d\n", dp.size());
    return 0;
}
