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