#include using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, M; cin >> N >> M; vector a; bool b = false; for (int i = 0; i < N; ++i) { int t; cin >> t; a.emplace_back(t); } vector< unordered_set > v(N, unordered_set()); for (int i = 0; i < M; ++i) { int u1, u2; cin >> u1 >> u2; v[u1-1].emplace(a[u2-1]); v[u2-1].emplace(a[u1-1]); } for (int i = 0; i < v.size(); ++i) { if (v[i].size() < 2) { continue; } int cnt; cnt = 0; for (auto &j : v[i]) { if (a[i] < j) { cnt += 1; } } if (cnt > 1) { b = true; break; } cnt = 0; for (auto &j : v[i]) { if (a[i] > j) { cnt += 1; } } if (cnt > 1) { b = true; break; } } cout << (b ? "YES" : "NO") << endl; return 0; }