import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto N = readln.chomp.to!int;
    auto A = N.iota.map!(_ => readln.chomp.to!int).array;
    auto S = new int[](100001);
    foreach (i; 0..100001)
        S[i] = int.max;
    S[0] = 0;
    S[1] = A[0];
    auto SS = S.assumeSorted;

    int ans = 1;
    foreach (i; 1..N) {
        auto lb = SS.lowerBound(A[i]).length.to!int;
        ans = max(ans, lb);
        if (S[lb] > A[i])
            S[lb] = A[i];
    }
    ans.writeln;
}