#include using namespace std; vector g[1005]; int main() { cin.tie(0); ios::sync_with_stdio(false); 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(a[v]); g[v].push_back(a[u]); } bool flag = false; for (int i = 0; i < n; i++) { sort(g[i].begin(), g[i].end()); g[i].erase(unique(g[i].begin(), g[i].end()), g[i].end()); int ui = upper_bound(g[i].begin(), g[i].end(), a[i]) - g[i].begin(); int li = lower_bound(g[i].begin(), g[i].end(), a[i]) - g[i].begin(); if (li >= 2 || (int)g[i].size() - ui >= 2) { flag = true; break; } } cout << (flag ? "YES" : "NO") << endl; return 0; }