import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.Map.Entry; import java.util.PriorityQueue; import java.util.Scanner; import java.util.TreeSet; public class Main { public static boolean find(int deep, int limit, int[] history, int node, int parent, int[] as, ArrayList> adj){ history[deep] = node; if(deep + 1 >= limit){ return true; } for(final int next : adj.get(node)){ if(next == parent){ continue; } if(deep == 0){ final int curr_as = as[history[deep]]; final int next_as = as[next]; if(curr_as == next_as){ continue; } }else if(deep == 1){ final int prev_as = as[history[deep - 1]]; final int curr_as = as[history[deep - 0]]; final int next_as = as[next]; if(prev_as == next_as || curr_as == next_as){ continue; } if(prev_as < curr_as && curr_as < next_as){ continue; } if(prev_as > curr_as && curr_as > next_as){ continue; } } if(find(deep + 1, limit, history, next, node, as, adj)){ return true; } } return false; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); final int M = sc.nextInt(); int[] as = new int[N]; for(int i = 0; i < N; i++){ as[i] = sc.nextInt(); } ArrayList> adj = new ArrayList>(); for(int i = 0; i < N; i++){ adj.add(new HashSet()); } for(int i = 0; i < M; i++){ final int a = sc.nextInt() - 1; final int b = sc.nextInt() - 1; adj.get(a).add(b); adj.get(b).add(a); } boolean ret = false; for(int i = 0; i < N; i++){ ret |= find(0, 3, new int[3], i, -1, as, adj); } System.out.println(ret ? "YES" : "NO"); } }