N, M = map(int, input().split()) A = list(map(int, input().split())) graph = [[] for _ in range(N)] for _ in range(M): u, v = map(int, input().split()) graph[u - 1].append(v - 1) graph[v - 1].append(u - 1) for i in range(N): lo = set() hi = set() for j in graph[i]: if A[i] < A[j]: hi.add(A[j]) if A[i] > A[j]: lo.add(A[j]) if len(hi) > 1 or len(lo) > 1: print('YES') break else: print('NO')