import java.io.*; import java.util.*; public class Main_yukicoder629 { private static Scanner sc; private static Printer pr; private static void solve() { int n = sc.nextInt(); int m = sc.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } List> edges = new ArrayList<>(n); for (int i = 0; i < n; i++) { edges.add(new ArrayList<>()); } for (int i = 0; i < m; i++) { int u = sc.nextInt() - 1; int v = sc.nextInt() - 1; edges.get(u).add(v); edges.get(v).add(u); } for (int i = 0; i < n; i++) { int x2 = a[i]; if (edges.get(i).size() >= 2) { for (int e1 : edges.get(i)) { int x1 = a[e1]; for (int e2 : edges.get(i)) { int x3 = a[e2]; if ((x2 > x1 && x2 > x3 && x1 != x3) || (x2 < x1 && x2 < x3 && x1 != x3)) { pr.println("YES"); return; } } } } } pr.println("NO"); } // --------------------------------------------------- public static void main(String[] args) { sc = new Scanner(System.in); pr = new Printer(System.out); solve(); pr.close(); sc.close(); } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }