from collections import defaultdict def main(): n, m = map(int, input().split()) a = [0] + list(map(int, input().split())) adj = defaultdict(set) for _ in range(m): fr, to = map(int, input().split()) if a[fr] != a[to]: adj[fr].add(to) adj[to].add(fr) for i in range(n + 1): if len(adj[i]) < 2: continue big = len(set([a[x] for x in adj[i] if a[x] > a[i]])) small = len(set([a[x] for x in adj[i] if a[x] < a[i]])) if big > 1 or small > 1: exit(print("YES")) print("NO") if __name__ == "__main__": main()