N,M = map(int,input().split()) A =[0]+list(map(int,input().split())) G = {i:[] for i in range(1,N+1)} for _ in range(M): u,v = map(int,input().split()) G[u].append(v) G[v].append(u) ans = "NO" for i in range(1,N+1): if len(G[i])<2:continue for j1 in range(len(G[i])-1): for j2 in range(j1+1,len(G[i])): u = G[i][j1] v = G[i][j2] if A[i]!=A[u] and A[u]!=A[v] and A[v]!=A[i] and min(A[i],A[u],A[v])==A[i]: ans = "YES" break if ans=="YES":break if ans=="YES":break print(ans)