N, M = gets.split.map &:to_i a = gets.split.map &:to_i edges = [] $<.map{|s| from, to = s.split.map(&:to_i).map &:pred edges << [from, to] << [to, from] } puts a.each_with_index.any?{|n, i| values = edges.select{|from, to| from == i}.map{|from, to| a[to]} next if values.size < 2 values.min(2).all?{|min| min < n} || values.max(2).all?{|max| max > n} } ? :YES : :NO