import java.util.Collections

fun main(args: Array<String>) {
    val n = readInputLine().toInt()

    val list = mutableListOf<Int>()

    list.add(readInputLine().toInt())

    for (i in 2..n) {
        val a = readInputLine().toInt()
        val index = findIndex(list, a)
        if (index >= list.size) {
            list.add(a)
        } else {
            list[index] = a
        }
    }

    println(list.size)
}

fun readInputLine(): String {
    return readLine()!!
}

fun <T: Comparable<T>> findIndex(list: List<T>, value: T): Int {
    return Collections.binarySearch(list, value, {x, y -> if (x < y) 1 else -1}).inv()
}
