#include #include #include template struct Edge { int src, dst; Cost cost; Edge(int src = -1, int dst = -1, Cost cost = 1) : src(src), dst(dst), cost(cost){}; bool operator<(const Edge& e) const { return this->cost < e.cost; } bool operator>(const Edge& e) const { return this->cost > e.cost; } }; template using Graph = std::vector>>; void solve() { int n, m; std::cin >> n >> m; std::vector xs(n); for (auto& x : xs) std::cin >> x; Graph<> graph(n); while (m--) { int u, v; std::cin >> u >> v; --u, --v; graph[u].emplace_back(u, v); graph[v].emplace_back(v, u); } for (int v = 0; v < n; ++v) { auto x = xs[v]; std::set ls, rs; for (auto e : graph[v]) { auto y = xs[e.dst]; if (y < x) ls.insert(y); if (y > x) rs.insert(y); } if (ls.size() > 1 || rs.size() > 1) { std::cout << "YES" << std::endl; return; } } std::cout << "NO" << std::endl; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }