n,m = map(int,input().split()) *a, = map(int,input().split()) g = [[] for _ in range(n)] for _ in range(m): x,y = map(int,input().split()) g[x-1].append(y-1) g[y-1].append(x-1) for x in range(n): le = mo = 0 for v in g[x]: if a[v] < x: le += 1 if a[v] > x: mo += 1 if le >= 2 or mo >= 2: print("YES") exit() print("NO")