import sys N, M = list(map(int, input().split())) a = list(map(int, input().split())) g = [[] for i in range(N)] for i in range(M): u, v = list(map(int, input().split())) u -= 1; v -= 1 g[u].append(v) g[v].append(u) for i in range(N): q = [v for v in g[i]] for v in q: n = [(a[i], a[v], a[u]) for u in g[v] if a[i] != a[u] and a[v] != a[u]] for s in n: if min(s) == a[v] or max(s) == a[v]: print('YES') sys.exit() print('NO')