#![allow(non_snake_case)] use std::collections::{ HashSet }; use std::io::{ self, prelude::* }; macro_rules! pick { ($tokens:expr) => { $tokens.next().unwrap().parse().expect("parse error") } } fn main() { let mut s = String::new(); io::stdin().read_to_string(&mut s).expect("i/o error"); let mut tokens = s.split_whitespace(); let N: usize = pick!(tokens); let M: usize = pick!(tokens); let mut A: Vec = Vec::with_capacity(N); let mut G: Vec> = vec![vec![]; N]; for _ in 0..N { A.push(pick!(tokens)); } for _ in 0..M { let mut i: usize = pick!(tokens); i -= 1; let mut j: usize = pick!(tokens); j -= 1; G[i].push(j); G[j].push(i); } for i in 0..N { let mut lts = HashSet::new(); let mut gts = HashSet::new(); for &j in &G[i] { if A[j] < A[i] { lts.insert(A[j]); } else if A[j] > A[i] { gts.insert(A[j]); } } if lts.len() >= 2 || gts.len() >= 2 { println!("YES"); return; } } println!("NO"); }