#include <iostream>
#include <set>

using namespace std;
typedef long long int ll;

int main() {
    // Optimize standard I/O operations for performance
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n;
    if (!(cin >> n)) return 0;

    multiset<ll> k;
    for (ll i = 0; i < n; i++) {
        ll val;
        cin >> val;
        
        // lower_bound returns an iterator to the first element >= val
        auto it = k.lower_bound(val);
        
        // If it's not the beginning, there is at least one element < val
        if (it != k.begin()) {
            --it; // Move back one step to get the largest element strictly < val
            k.erase(it); // Erase the found element
        }
        
        // Insert the current element
        k.insert(val);
    }
    
    cout << k.size() << "\n";
    
    return 0;
}