import sys readline = sys.stdin.readline sys.setrecursionlimit(10**7) def kadomatsu(a, b, c): for i in [-1, 1]: if a * i < b * i and b * i > c * i and a != c: return True return False def dfs(s, L, p=-1): if len(L) == 3: if kadomatsu(A[L[0]], A[L[1]], A[L[2]]): print("YES") exit() return for u in G[s]: if u == p: continue L.append(u) dfs(u, L) L.pop() return N, M = map(int, readline().split()) A = list(map(int, readline().split())) G = [[] for i in range(N)] for i in range(M): u, v = map(int, readline().split()) u, v = u - 1, v - 1 if A[u] == A[v]: continue G[u].append(v) G[v].append(u) for i in range(N): dfs(i, [i]) print("NO")