import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N = lread();
    auto A = new long[](N);
    foreach (i; 0 .. N)
        A[i] = lread();
    auto dp = new long[](N + 1);
    dp[] = long.min;
    dp[0] = long.max;
    long ans = long.min;
    foreach (i; 0 .. N)
    {
        long j = () {
            long ok = 0;
            long ng = N + 2;
            while (1 < ng - ok)
            {
                long m = (ng + ok) / 2;
                if (A[i] <= dp[m])
                {
                    ok = m;
                }
                else
                {
                    ng = m;
                }
            }
            return ng;
        }();
        dp[j] = A[i];
        ans = ans.max(j);
    }
    writeln(ans);
}
