input_lines = gets.to_i
b = Array.new(0)
c = Array.new(0)
b.push(0)
c.push(0)
res = "YES"
input_lines.times{
  s = gets.chomp.split(" ")
  s.map! {|x| x.to_i}
  b.push(s[0])
  for num in 1..9 do
   if b.last < s[num] && c.last >= s[num] then
     b.push(s[num])
   elsif b.last >= s[num] && c.last < s[num] then
     c.push(s[num])
   elsif b.last < s[num] && c.last < s[num] then
     if b.last < c.last then
       c.push(s[num])
     else
       b.push(s[num])
     end
   else
     res =  "NO"
     break
   end
  end
puts res
}