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