#include <stdio.h>
#define N_MAX 100000
#define A_MAX (1e9+1)

int main() {
    int i, n, m, a[N_MAX];
    scanf("%d", &n);
    for (i=0; i<n; i++) a[i] = A_MAX;
    while (~scanf("%d", &m)) {
        int x = 0, y = n - 1;
        while (x != y) {
            int z = (x + y) / 2;
            if (m > a[z]) x = z + 1;
            else if (m <= a[z]) y = z;
        }
        a[x] = m;
    }
    for (i=n-1; a[i]==A_MAX; i--);
    printf("%d\n", i+1);
}

