#include using namespace std; #define rep(i, j, n) for(int i=j;i pi; template using vt = vector; template using vvt = vector>; i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));} i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);} int dx[] = {0, 1, 0, -1}; int dy[] = {1, 0, -1, 0}; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; vt a(n); rep(i, 0, n) cin >> a[i]; vt> edge(n); rep(i, 0, m) { int u, v; cin >> u >> v; u--; v--; edge[u].insert(v); edge[v].insert(u); } rep(i, 0, n) { rep(j, i + 1, n) { for(auto nxt : edge[i]) { if(nxt == j || !edge[j].count(nxt)) continue; if(a[nxt] > a[i] && a[nxt] > a[j] && a[i] != a[j]) return cout << "YES\n", 0; } } } cout << "NO\n"; }