#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<int> d(n+1, 1000000000);
for (int i = 0; i < n; i++) {
*lower_bound(d.begin(), d.end(), a[i]) = a[i];
}
for (int i = 0; i <= n; i++) {
if (d[i] == 1000000000) {
cout << i << endl;
return 0;
}
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CglpbnQgbjsKCWNpbiA+PiBuOwoJdmVjdG9yPGludD4gYShuKTsKCWZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSB7CgkJY2luID4+IGFbaV07Cgl9Cgl2ZWN0b3I8aW50PiBkKG4rMSwgMTAwMDAwMDAwMCk7Cglmb3IgKGludCBpID0gMDsgaSA8IG47IGkrKykgewoJCSpsb3dlcl9ib3VuZChkLmJlZ2luKCksIGQuZW5kKCksIGFbaV0pID0gYVtpXTsKCX0KCWZvciAoaW50IGkgPSAwOyBpIDw9IG47IGkrKykgewoJCWlmIChkW2ldID09IDEwMDAwMDAwMDApIHsKCQkJY291dCA8PCBpIDw8IGVuZGw7CgkJCXJldHVybiAwOwoJCX0KCX0KfQo=