import sys N, M = map(int, input().split()) l = list(map(int, input().split())) conect_l = [[] for i in range(N)] for i in range(M): node1, node2 = map(int, input().split()) conect_l[node1 - 1].append(l[node1 - 1] - l[node2 - 1]) conect_l[node2 - 1].append(l[node2 - 1] - l[node1 - 1]) for i in range(M): s = set(conect_l[i]) ck = list(s) posi_n = 0 nega_n = 0 for l_i in ck: if l_i > 0: posi_n += 1 if l_i < 0: nega_n += 1 if posi_n >= 2: print("YES") sys.exit() if nega_n >= 2: print("YES") sys.exit() print("NO")