#include using namespace std; int a[1001]; vector adj[1001]; int n, m, u, v; int main(void) { cin.tie(0); ios::sync_with_stdio(false); cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } for (int i = 1; i <= n; i++) { int L = 0; int R = 0; set S; for (auto j : adj[i]) { if (S.find(a[j]) == S.end()) { if (a[j] > a[i]) R++; else if (a[j] < a[i]) L++; S.insert(a[i]); } if (L == 2 || R == 2) { cout << "YES" << '\n'; return 0; } } } cout << "NO" << '\n'; return 0; }