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 = set() mo = set() for v in g[x]: if a[v] < a[x]: if le and a[v] not in le: print("YES") exit() le.add(a[v]) if a[v] > a[x]: if mo and a[v] not in mo: print("YES") exit() print("NO")