#include using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) int n, m; int a[1000]; vector edges[1000]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; REP (i, n) cin >> a[i]; REP (i, m) { int u, v; cin >> u >> v; --u, --v; edges[u].push_back(v); edges[v].push_back(u); } bool ret = false; REP (i, n) { int x2 = a[i]; REP (j, edges[i].size()) REP (k, edges[i].size()) { int x1 = edges[i][j]; int x3 = edges[i][k]; if (x1 == x2 || x2 == x3 || x3 == x1) continue; if (x2 == max({x1, x2, x3}) || x2 == min({x1, x2, x3})) ret = true; } } cout << (ret ? "YES" : "NO") << endl; return 0; }