def binary_search(array, target)
  head = 0
  tail = array.count - 1
  
  while head <= tail
    center = (head + tail) / 2
    if array[center] == target
      return center
    elsif array[center] < target
      head = center + 1
    else
      tail = center - 1
    end
  end
  tail
end

N = gets.to_i
array = []
N.times do
  val = gets.to_i
  diff = 1_000_000_001
  idx = nil
  if !array.empty? && array[0] < val
    idx = binary_search(array, val-1)
    idx += 1 if idx <= array.length-2 && array[idx+1] < val
  end
  if idx.nil?
    array.unshift(val)
  else
    array[idx] = val
    ((idx+1)..(array.length-1)).each do |i|
      break if array[i] >= array[i-1]
      array[i-1], array[i] = array[i], array[i-1]
    end
  end
  # puts "#{array}"
end

puts array.length
