n = gets.to_i
a = []
n.times{ a << gets.to_i }
dp =  Array.new(n)
dp[0] = a[0]
l = 1
(1..n-1).each do |i|
  if dp[l-1] < a[i]
    dp[l] = a[i]
    l += 1
  else
    left = 0
    right = l-1
    mid = (left + right)/2
    while left < right
      mid = (left + right)/2
      if a[i] > dp[mid]
        right = mid
      else
        left = mid
      end
    end
    dp[mid] = a[i]
  end
end
p l