#include #include #include #include #include using namespace std; int main() { int n, m; cin >> n >> m; vector a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector> g(n); 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 i = 0; i < n; i++) { vector v; for (int j : g[i]) { v.push_back(a[j]); } sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); int l = int(lower_bound(v.begin(), v.end(), a[i]) - v.begin()) - 1; int r = upper_bound(v.begin(), v.end(), a[i]) - v.begin(); if (l >= 1 || r + 2 <= v.size()) { cout << "YES" << endl; return 0; } } cout << "NO" << endl; }