import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int[] arr = new int[n + 1]; TreeSet[] graph = new TreeSet[n + 1]; for (int i = 1; i <= n; i++) { arr[i] = sc.nextInt(); graph[i] = new TreeSet(); } for (int i = 0; i < m; i++) { int a = sc.nextInt(); int b = sc.nextInt(); graph[a].add(arr[b]); graph[b].add(arr[a]); } for (int i = 1; i <= n; i++) { Integer small = graph[i].lower(arr[i]); if (small != null) { if (graph[i].lower(small) != null) { System.out.println("YES"); return; } } Integer large = graph[i].higher(arr[i]); if (large != null) { if (graph[i].higher(large) != null) { System.out.println("YES"); return; } } } System.out.println("NO"); } }