def kadomatsu(a,b,c): if min(a,b,c)==b or max(a,b,c)==b and a!=b and b!=c and c!=a: return True else: return False n,m=map(int,input().split()) a=[0]+list(map(int,input().split())) g=[[] for _ in range(n+1)] for _ in range(m): x,y=map(int,input().split()) g[x].append(y) g[y].append(x) f=False for p in range(1,n+1): if len(g[p])<2: continue for i in range(len(g[p])): for j in range(i+1,len(g[p])): if kadomatsu(a[g[p][i]],a[p],a[g[p][j]]): f=True break print('YES' if f else 'NO')