N, M = map(int, input().split()) a = list(map(int, input().split())) g = [[] for _ in range(N)] for i in range(M): u, v = map(int, input().split()) if not a[u - 1] == a[v - 1]: g[u - 1].append(a[v - 1]) g[v - 1].append(a[u - 1]) for i, n in enumerate(g): ns = list(set(g[i])) length = len(ns) if length > 2: print('YES') exit() elif length == 2: if (ns[0] < a[i] and ns[1] < a[i]) or (ns[0] > a[i] and ns[1] > a[i]): print('YES') exit() print('NO')