import std.stdio, std.conv, std.string, std.algorithm, std.range;

void main()
{
    immutable n = readln.chomp.to!int;
    int[] T = new int[n+1];
    auto V = assumeSorted(new int[n+1]);

    for( int i=0; i<n; ++i ) {
        T[i] = readln.chomp.to!int;
    }

    V[0] = T[0];
    int length = 1;
    for( int i=1; i<n; ++i ) {
        if ( T[length] < T[i] ) {
            V[length] = T[i];
            ++length;
        } else {
            auto j = V[0..length].lowerBound(T[i]);
            V[j.length] = T[i];
        }
    }
    length.writeln;
}