import sys input = sys.stdin.readline N,M=map(int,input().split()) A=list(map(int,input().split())) E=[[] for i in range(N)] for i in range(M): x,y=map(int,input().split()) x-=1 y-=1 E[x].append(y) E[y].append(x) for i in range(N): a=A[i] for to in E[i]: b=A[to] for toto in E[to]: c=A[toto] if ac and a!=c: print("YES") exit() if a>b and b