#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,n) for(int i=0; i=b; --i) #define ALL(c) (c).begin(), (c).end() typedef long long ll; typedef vector VI; typedef vector VL; typedef vector VVI; typedef vector VVL; typedef pair P; typedef pair PL; int main() { int n, m; cin >> n >> m; VI a(n); REP(i,n) cin >> a[i]; vector

e(m); REP(i,m){ cin >> e[i].first >> e[i].second; if (e[i].first > e[i].second) swap(e[i].first, e[i].second); e[i].first--; e[i].second--; } sort(ALL(e)); REP(j,m) REP(i,j){ if (e[i].second == e[j].first){ int p = e[i].first; int q = e[j].second; int r = e[i].second; if (a[p] != a[q] && (a[r] > max(a[p], a[q]) || a[r] < min(a[p], a[q]))){ cout << "YES" << endl; return 0; } } if (e[i].second == e[j].second){ int p = e[i].first; int q = e[j].first; int r = e[i].second; if (a[p] != a[q] && (a[r] > max(a[p], a[q]) || a[r] < min(a[p], a[q]))){ cout << "YES" << endl; return 0; } } } cout << "NO" << endl; return 0; }