def lower_bound(a, l, r, v)
	m = l
	until m == r
		l, r = a[m] < v ? [m, r] : [l, m]
		m = l + (r-l+1)/2
	end
	return m
end

N  = gets.to_i
probes = []

N.times{
	a = gets.to_i
	i = lower_bound(probes, 0, probes.length, a)
	if i == 0
		probes.unshift(a)
	else
		probes[i-1] = a
	end
p probes
}

p probes.length
