n, m = map(int, input().split()) A = list(map(int, input().split())) up = [set() for _ in range(n)] down = [set() for _ in range(n)] for _ in range(m): u, v = map(int, input().split()) u -= 1 v -= 1 if A[u] < A[v]: up[u].add(v) down[v].add(u) elif A[u] > A[v]: up[v].add(u) down[u].add(v) for i in range(n): if len(up) >= 2 or len(down) >= 2: print("YES") break else: print("NO")