N,*A = `dd`.split.map &:to_i
colors = []
A.each{ |a|
  m = colors.size
  j = (0...colors.size).bsearch{ |i|
    colors[m-i-1] < a
  }
  if j
    colors[m-j-1] = a
  else
    colors << a
  end
}
p colors.size
