fun main() {
    val n= readLine()!!.toInt()
    val a= IntArray(n){ readLine()!!.toInt()}
    fun IntArray.lowerBounds(e:Int):Int{
        var l=-1
        var r=this.size
        while (r-l>1){
            val mid=(l+r)/2
            if (this[mid]<e){l=mid}
            else{r=mid}
        }
        return l
    }
    var dp=IntArray(n){ -1}
    for (i in a){
        val ind=dp.lowerBounds(i)
        dp[ind]=i
    }
    var ans=n-dp.count { it==-1 }
    println(ans)
}