def isTrees(x1, x2, x3): if x1 != x3 and ((x2 > x1 and x2 > x3) or (x2 < x1 and x2 < x3)): return True else: return False n,m = input().split(' ') a = [] a = input().split(' ') v = [] for i in range(0,int(m)): v.append(input().split(' ')) result = 'NO' for i in range(0,int(m)): for j in range(i + 1, int(m)): if i != j: if v[i][0] in v[j]: t = 1 if(v[j].index(v[i][0]) == 0) else 0 if isTrees(a[int(v[j][t])-1], a[int(v[i][0])-1], a[int(v[i][1])-1]): result = 'YES' if v[i][1] in v[j]: t = 1 if(v[j].index(v[i][1]) == 0) else 0 if isTrees(a[int(v[j][t])-1], a[int(v[i][1])-1], a[int(v[i][0])-1]): result = 'YES' if result == 'YES': break print(result)