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

void main() {
    int n;
    int[] a;

    scan(n);
    a = iota(n).map!(i => readln.chomp.to!int).array;

    auto dp = repeat(10^^9 + 7, n + 2).array.assumeSorted;
    dp[0] = -1;

    int ans = 1;

    foreach (i ; 0 .. n) {
        auto j = dp.lowerBound(a[i]).length;
        dp[j] = a[i];
        ans = max(ans, j);
    }

    writeln(ans);
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.array : split;
    import std.conv  : to;
    import std.range.primitives;

    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}
