#include "bits/stdc++.h" #define REP(i, n, N) for(ll i=(n); i<(N); i++) #define RREP(i, n, N) for(ll i=(N-1); i>=n; i--) #define SPACEREP(lst,itr) for(auto itr=lst.begin(); itr!=lst.end();++itr){cout<<*itr<<(++itr!=anslist.end()?" ":"\n");itr--;} #define CK(n, a, b) ((a)<=(n)&&(n)<(b)) #define ALL(v) (v).begin(),(v).end() #define MCP(a, b) memcpy(b,a,sizeof(b)) #define p(s) cout<<(s)<> typedef long long ll; using namespace std; const ll mod = 1e9 + 7; const ll inf = 1e18; int main(){ int N,M; cin >> N >> M; vector>> edge(N+1); vector value(N+1); int u,v; REP(i,1,N+1){ cin >> value[i]; } REP(i,1,M+1){ cin >> u >> v; if(value[u]-value[v]==0)continue; edge[u].push_back(make_pair(v,value[u]-value[v])); edge[v].push_back(make_pair(u,value[v]-value[u])); } bool flag=false; REP(i,1,N+1){ for(auto x : edge[i]){ for(auto y : edge[i]){ if(x.first==y.first)continue; if(x.second==y.second)continue; if(x.second<0 && y.second>0)continue; if(x.second>0 && y.second<0)continue; flag=true; } } } cout << (flag ? "YES" : "NO") << endl; }