import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import itertools N,M = map(int,readline().split()) A = [0] + list(map(int,readline().split())) m = map(int,read().split()) UV = zip(m,m) find = False for (u1,v1),(u2,v2) in itertools.combinations(UV,2): if u1 == u2: a,b,c = v1,u1,v2 elif u1 == v2: a,b,c = v1,u1,u2 elif v1 == u2: a,b,c = u1,v1,v2 elif v1 == v2: a,b,c = u1,v1,u2 else: continue a,b,c = A[a], A[b], A[c] if a == c: continue if a > b < c or a < b > c: find = True break answer = 'YES' if find else 'NO' print(answer)