#yuki629 N,M=map(int,raw_input().split()) A=map(int,raw_input().split()) E=[[] for i in xrange(N)] for i in xrange(M): a,b=map(int,raw_input().split()) a,b=a-1,b-1 E[a].append(b) E[b].append(a) res='NO' for cu in xrange(N): up=set() dn=set() for to in E[cu]: if A[cu]A[to]: dn.add(A[to]) if len(up)>=2: res='YES' if len(dn)>=2: res='YES' print res