import sys from itertools import permutations def main(): n, m = map(int, sys.stdin.readline().split()) a = list(map(int, sys.stdin.readline().split())) adj = [[] for _ in range(n + 1)] # Using 1-based index for vertices for _ in range(m): u, v = map(int, sys.stdin.readline().split()) adj[u].append(v) adj[v].append(u) for b in range(1, n + 1): neighbors = adj[b] if len(neighbors) < 2: continue for a_node, c_node in permutations(neighbors, 2): x1 = a[a_node - 1] x2 = a[b - 1] x3 = a[c_node - 1] if x1 == x2 or x2 == x3 or x1 == x3: continue if (x2 > x1 and x2 > x3) or (x2 < x1 and x2 < x3): print("YES") return print("NO") if __name__ == "__main__": main()