N, M = map(int, input().split()) A = list(map(int, input().split())) G = [[]] * N for _ in range(M): u, v = map(int, input().split()) u -= 1 v -= 1 G[u].append(v) G[v].append(u) for u in range(N): if (len(G[u]) < 2): continue less = set() more = set() for v in G[u]: if A[v] < A[u]: less.add(A[v]) if A[v] > A[u]: more.add(A[v]) if len(less) >= 2 or len(more) >= 2: print("YES") break else: print("NO")