import numpy as np import sys N, M = map(int, input().split()) l = list(map(int, input().split())) A = np.zeros((N,N)) for i in range(M): node1, node2 = map(int, input().split()) A[node1 - 1, node2 - 1] = 1 A[node2 - 1, node1 - 1] = 1 AA = np.dot(A,A) for i in range(N): for j in range(i + 1, N): if AA[i, j] > 0: ck = A[i] + A[j] for k in range(N): if ck[k] == 2: if max(l[k],l[i],l[j]) == l[k] and len(set([l[k],l[i],l[j]])) == 3: print("YES") sys.exit() if min(l[k],l[i],l[j]) == l[k] and len(set([l[k],l[i],l[j]])) == 3: print("YES") sys.exit() print("NO")