#include #define rep(i,n) for(int i=0;i<(int)(n);i++) using namespace std; using ll = long long ; using P = pair ; using pll = pair; constexpr int INF = 1e9; constexpr long long LINF = 1e17; constexpr int MOD = 1000000007; int n = 1005,m; vector> graph(n,vector()); vector a(n); bool iskadomatu(vector v){ if(v[0] == v[1] || v[1] == v[2] || v[0] == v[2]) return false; if(v[1] > v[0] && v[1] > v[2]) return true; if(v[1] < v[0] && v[1] < v[2]) return true; return false; } bool dfs(int i,vector v,int p=-1){ if((int)(v.size()) == 3){ if(iskadomatu(v)) return true; else return false; } bool res = false; for(int c:graph[i]){ if(c==p) continue; v.push_back(a[c]); res = res || dfs(c,v,i); v.pop_back(); } return res; } int main(){ cin >> n >> m; rep(i,n) cin >> a[i]; rep(i,m){ int u,v; cin >> u >> v; --u;--v; graph[u].push_back(v); graph[v].push_back(u); } vector v; rep(i,n){ v.push_back(a[i]); if(dfs(i,v)){ cout << "YES" << endl; return 0; } v.pop_back(); } cout << "NO" << endl; return 0; }