n, m = map(int, input().split()) A = list(map(int, input().split())) edge = [] for _ in range(m): u, v = map(int, input().split()) u -= 1 v -= 1 if u > v: u, v = v, u edge.append((u, v)) for i in range(m): u1, v1 = edge[i] for j in range(i + 1, m): u2, v2 = edge[j] if u1 == u2: x, y, z = A[v1], A[u1], A[v2] elif u1 == v2: x, y, z = A[v1], A[u1], A[u2] elif v1 == u2: x, y, z = A[u1], A[v1], A[v2] elif v1 == v2: x, y, z = A[u1], A[v1], A[u2] else: continue if x == y or x == z or y == z: continue if x < y > z or x > y < z: print("YES") exit() print("NO")