N = gets.chomp.to_i
AS = []
N.times { AS.push(gets.chomp.to_i) }

arr = [AS[0]]
arr2 = [[AS[0]]]

1.upto(N - 1) do |i|
  if AS[i] <= arr[0]
    arr.unshift(AS[i])
    arr2.unshift([AS[i]])
    next
  end
  if AS[i] > arr[-1]
    arr[-1] = AS[i]
    arr2[-1].push(AS[i])
    next
  end
  a = 0
  b = arr.size - 1
  while a < b
    c = (a + b) / 2
    if arr[c + 1] < AS[i]
      a = [c, a + 1].max 
    elsif arr[c] >= AS[i]
      b = [c, b - 1].min
    else
      a = b = c
    end
  end
  arr[c] = AS[i]
  arr2[c].push(AS[i])
end

puts arr.size
