import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); int M = scan.nextInt(); int[]a = new int[N]; for(int i = 0; i < N; i++) { a[i] = scan.nextInt(); } int[]u = new int[M]; int[]v = new int[M]; for(int i = 0; i < M; i++) { u[i] = scan.nextInt(); v[i] = scan.nextInt(); } scan.close(); Map> G = new HashMap>(); for(int i = 0; i < M; i++) { if(G.containsKey(u[i])) { G.get(u[i]).add(v[i]); }else { ArrayList list = new ArrayList(); list.add(v[i]); G.put(u[i], list); } if(G.containsKey(v[i])) { G.get(v[i]).add(u[i]); }else { ArrayList list = new ArrayList(); list.add(u[i]); G.put(v[i], list); } } for(int k : G.keySet()) { ArrayList list = G.get(k); if(list.size() >= 2) { int t1 = a[k - 1]; Set up = new HashSet(); Set dw = new HashSet(); for(int i = 0; i < list.size(); i++) { if(t1 > a[list.get(i) - 1]) { up.add(a[list.get(i) - 1]); }else if(t1 < a[list.get(i) - 1]) { dw.add(a[list.get(i) - 1]); } } if(up.size() >= 2 || dw.size() >= 2) { System.out.println("YES"); System.exit(0); } } } System.out.println("NO"); } }