#include <iterator>
#include <cstdio>
#include <set>
using namespace std;
int main()
{
int n;
scanf ("%d", &n);
int a[n];
for (int i = 0; i < n; ++i)
scanf ("%d", &a[i]);
set<int> st;
set<int>::iterator it;
st.clear();
for (int i = 0; i < n; ++i)
{
st.insert(a[i]);
it = st.find(a[i]);
++it;
if (it != st.end())
st.erase(a[i]);
}
printf ("%d\n",st.size());
return 0;
}
I2luY2x1ZGUgPGl0ZXJhdG9yPgojaW5jbHVkZSA8Y3N0ZGlvPgojaW5jbHVkZSA8c2V0Pgp1c2luZyBuYW1lc3BhY2Ugc3RkOwppbnQgbWFpbigpIAp7CglpbnQgbjsKCXNjYW5mICgiJWQiLCAmbik7CglpbnQgYVtuXTsKCWZvciAoaW50IGkgPSAwOyBpIDwgbjsgKytpKQoJCXNjYW5mICgiJWQiLCAmYVtpXSk7CglzZXQ8aW50PiBzdDsKCXNldDxpbnQ+OjppdGVyYXRvciBpdDsKCXN0LmNsZWFyKCk7Cglmb3IgKGludCBpID0gMDsgaSA8IG47ICsraSkKCXsKCQlzdC5pbnNlcnQoYVtpXSk7CgkJaXQgPSBzdC5maW5kKGFbaV0pOwoJCSsraXQ7CgkJaWYgKGl0ICE9IHN0LmVuZCgpKQoJCQlzdC5lcmFzZShhW2ldKTsKCX0KCXByaW50ZiAoIiVkXG4iLHN0LnNpemUoKSk7CglyZXR1cm4gMDsKfQ==