#include using namespace std; typedef long long ll; #define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++) #define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++) #define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--) #define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--) #define all(x) (x).begin(), (x).end() #define sz(x) ((ll)(x).size()) #define len(x) ((ll)(x).length()) int main() { cin.tie(0); ios::sync_with_stdio(false); // ifstream in("input.txt"); // cin.rdbuf(in.rdbuf()); ll n, m; cin >> n >> m; vector a(n); rep(i, n) cin >> a[i]; vector> g(n); rep(i, m) { ll u, v; cin >> u >> v; u--; v--; g[u].insert(a[v]); g[v].insert(a[u]); } rep(i, n) { vector vs; for(auto x : g[i]) vs.push_back(x); auto it = lower_bound(all(vs), a[i]); ll left = it - vs.begin(); if (left >= 2) { cout << "YES" << endl; return 0; } ll right = sz(vs) - left; if (right >= 2) { cout << "YES" << endl; return 0; } } cout << "NO" << endl; return 0; }