#include <stdio.h>
#include <stdlib.h>

int lower_bound(int *a, int n, int x)
{
    int lf = 0, rg = n - 1;

    while (lf != rg){
        int mid = (lf + rg) / 2;
        if (a[mid] >= x) rg = mid;
        else lf = mid + 1;
    }

    return (lf);
}

int main(void)
{
    int i, n;
    int *dp;
    int a;

    scanf("%d", &n);
    dp = (int *)malloc(sizeof(int) * (n + 1));

    for (i = 0; i <= n; i++) dp[i] = 1001001001;

    for (i = 0; i < n; i++){
        scanf("%d", &a);
        dp[lower_bound(dp, n + 1, a)] = a;
    }

    printf("%d\n", lower_bound(dp, n + 1, 1001001001));

    return (0);
}