import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int[] a) {
    auto dq = new Deque!int(a.length);
    dq.pushBack(a[0]);
    foreach (e; a.drop(1)) {
        int lo = 0;
        int hi = dq.size() - 1;
        int best = hi + 1;
        while (lo <= hi) {
            int m = (lo + hi) / 2;
            if (dq[m] >= e) {
                best = min(best, m);
                hi = m - 1;
            } else lo = m + 1;
        }

        if (best == 0) dq.pushFront(e);
        else dq[best-1] = e;
    }
    return dq.size();
}

void main() {
    int n = readint;
    int[] a;
    foreach (_; 0..n) a ~= readint;
    writeln(calc(a));
}

class Deque(T) {
    private T[] _buffer;
    private size_t _size;
    private int _front;
    private int _back;

    this(size_t size) {
        _buffer = new T[size * 3];
        _size = 0;
        _front = _back = cast(int)size * 3 / 2;
    }

    @property bool empty() {
        return _size == 0;
    }

    int size() {
        return cast(int)_size;
    }

    void pushFront(T elt) {
        _buffer[empty ? _front : --_front] = elt;
        _size++;
    }

    void pushBack(T elt) {
        _buffer[empty ? _back : ++_back] = elt;
        _size++;
    }

    T opIndex(size_t index) {
        return _buffer[_front + index];
    }

    T opIndexAssign(T value, size_t index) {
        return _buffer[_front + index] = value;
    }
}
