n, m = map(int, input().split()) A = list(map(int, input().split())) #g = [[] for i in range(n)] X = [set() for i in range(n)] import bisect for i in range(m): u, v = map(int, input().split()) u, v = u-1, v-1 X[u].add(A[v]) X[v].add(A[u]) X = [sorted(list(s)) for s in X] #print(X) for i in range(n): if len(X[i]) <= 0: continue j = bisect.bisect_left(X[i], A[i]) k = bisect.bisect_right(X[i], A[i]) if j >= 2 or len(X[i])-k >= 2: print('YES') exit() else: print('NO')