
fun main(args: Array<String>) {
    val (n) = readLine()!!.split(' ').map(String::toInt)
    val xs = (1..n).map { readLine()!!.toInt() }
    val ret = Array(n){Int.MIN_VALUE}
    ret[0] = xs[0]
    var maxPointer = 0

    for(i in 1 until n){
        if(xs[i] <= ret[maxPointer]){
            ret[++maxPointer] = xs[i]
            continue
        }
        var max = maxPointer
        var min = 0
        val v = xs[i]
        while(max - min >= 0){
            val pos = (max + min) / 2
            val cur = ret[pos]
            if(v > cur){
                max = pos - 1
            }else{
                min = pos + 1
            }
        }
        ret[min] = v
    }
    print(maxPointer + 1)
}