N = gets.to_i
Ss = gets.split.map(&:to_i)

def born(xs, ys)
  return true if ys.empty?
  zs = []
  xs.reverse_each do |x|
    return false if x <= ys.last
    zs << ys.pop
  end
  born((xs + zs).sort, ys)
end

puts born([Ss.max], Ss.sort[0 ... -1]) ? 'Yes' : 'No'