def kadomatu(x, y, z): if x != y and y != z and z != x: if (y < x and y < z) or (y > x and y > z): return True def check(): N, M = map(int, input().split()) a = list(map(int, input().split())) u = [0] * M v = [0] * M for i in range(M): u[i], v[i] = map(int, input().split()) for i in range(M): for j in range(i + 1, M): if u[j] == v[i]: if kadomatu(a[u[i]-1], a[v[i]-1], a[v[j]-1]): return True if v[j] == v[i]: if kadomatu(a[u[i]-1], a[v[i]-1], a[u[j]-1]): return True for i in range(M): u[i], v[i] = v[i], u[i] for i in range(M): for j in range(i + 1, M): if u[j] == v[i]: if kadomatu(a[u[i]-1], a[v[i]-1], a[v[j]-1]): return True if v[j] == v[i]: if kadomatu(a[u[i]-1], a[v[i]-1], a[u[j]-1]): return True return False if check(): print("YES") else: print("NO")