n, m = io.read("*n", "*n") nodes = {} for i = 1, n do t = {} t["val"] = io.read("*n") t["count"] = 0 nodes[i] = t end found = false for i = 1, m do a, b = io.read("*n", "*n") ta, tb = nodes[a], nodes[b] cnt = ta["count"] if(cnt == 2) then found = true do break end else cnt = cnt + 1 ta["count"], ta[cnt] = cnt, b end cnt = tb["count"] if(cnt == 2) then found = true do break end else cnt = cnt + 1 tb["count"], tb[cnt] = cnt, a end end if(not found) then for i = 1, n do t = nodes[i] if(t["count"] == 2) then v = t["val"] v1t, v2t = nodes[t[1]], nodes[t[2]] v1, v2 = v1t["val"], v2t["val"] if(((v1 < v and v2 < v) or (v < v1 and v < v2)) and (v1 ~= v2)) then found = true break end end end end print (found and "YES" or "NO")