N = gets.to_i

queue = []
N.times do
	a = gets.to_i
	if queue.empty?
		queue.push(a)
		next
	end
	if queue[0] >= a
		queue.unshift(a)
	elsif queue[-1] < a
		queue[-1] = a
	else
		len = queue.size
		s = 0
		t = len - 1
		while true
			if queue[s] < a && queue[s + 1] >= a
				queue[s] = a
				break
			end
			n = (s + t) / 2
			if queue[n] < a
				s, t = n, t
			else
				s, t = s, n
			end
		end
	end
end

puts queue.size