#include #include #include using namespace std; using int64 = long long; vector G[1010]; int main() { int N, M; cin >> N >> M; vector a(N); for (int i = 0; i < N; i++) { cin >> a[i]; } for (int i = 0; i < M; i++) { int u, v; cin >> u >> v; u--; v--; G[u].push_back(v); G[v].push_back(u); } for (int v = 0; v < N; v++) { vector b; for (int to : G[v]) { b.push_back(a[to]); } sort(b.begin(), b.end()); b.erase(unique(b.begin(), b.end()), b.end()); if (b.size() < 2) continue; // a[v]が最小 if (b[b.size() - 2] > a[v]) { cout << "YES" << endl; return 0; } // a[v]が最大 if (b[1] < a[v]) { cout << "YES" << endl; return 0; } } cout << "NO" << endl; return 0; }