import java.util.*

fun search(a: MutableList<Int>, x: Int, l: Int, r: Int): Int {
    if (1 >= r - l) {
        return l
    } else {
        val m = (l + r) / 2
        if (a[m] >= x) {
            return search(a, x, l, m)
        } else {
            return search(a, x, m, r)
        }
    }
}


fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    val n = cin.nextInt()
    val a = Array<Int>(n, { cin.nextInt() })
    
    val roots: MutableList<Int> = mutableListOf(a[0])
    for (i in 1..n-1) {
        val k = search(roots, a[i], -1, roots.size)
        if (k == -1) {
            roots.add(0, a[i])
        } else {
            roots[k] = a[i]
        }
    }

    println(roots.size)
}