#include "bits/stdc++.h" using namespace std; #define DEBUG(x) cout<<#x<<": "< #define vl vector #define vii vector< vector > #define vll vector< vector > #define vs vector #define pii pair #define pis pair #define psi pair #define pll pair const int inf = 1000000001; const ll INF = 2e18 * 2; #define MOD 1000000007 #define mod 1000000009 #define pi 3.14159265358979323846 #define Sp(p) cout<> n >> m; vi a(n); for (i = 0; i < n; i++) { cin >> a[i]; } vii edge(m, vi(2)); for (i = 0; i < m; i++) { cin >> edge[i][0] >> edge[i][1]; edge[i][0]--; edge[i][1]--; } for (i = 0; i < m; i++) { for (j = i + 1; j < m; j++) { for (int k = 0; k < 2; k++) { for (int l = 0; l < 2; l++) { if (edge[i][k] == edge[j][l]) { int a0 = a[edge[i][1 - k]]; int a1 = a[edge[i][k]]; int a2 = a[edge[j][1 - l]]; if ((a1 - a0)*(a1 - a2) > 0 && a0 != a2) { cout << "YES" << endl; return 0; } } } } } } cout << "NO" << endl; }