def dfs(i, l): if len(l) == 3: if (l[1] == max(l) or l[1] == min(l)) and l[0] != l[1] and l[1] != l[2] and l[2] != l[0]: print("YES") exit() return for v in G[i]: l.append(A[v]) dfs(v, l) l.pop() N, M = map(int, input().split()) A = list(map(int, input().split())) G = [[]] * N for _ in range(M): u, v = map(int, input().split()) u -= 1 v -= 1 G[u].append(v) G[v].append(u) for i in range(N): l = [A[i]] dfs(i, l) print("NO")