#include #include #include #include #include #include #define For(i, N) for (i = 0; i < N; i++) #define rep(N) for (int i = 0; i < N; i++) #define re return 0 using namespace std; using ll = long long int; using vi = vector; using vb = vector; using vs = vector; using pib = pair; using pii = pair; template void say(T s) { cout << s << endl; } int main() { int N, M; cin >> N >> M; int A; int U, V; int i, j; vector a; vector u; rep(N) { cin >> A; a.push_back(A); } rep(M) { cin >> U >> V; u.push_back({ U - 1,V - 1 }); } for (i = 0; i < M; i++) for (j = i; j < M; j++) { int x, y, z; bool flag = false; x = u[i].first; y = u[i].second; if (u[i].first == u[j].first || u[i].second == u[j].first) { z = u[j].second; flag = true; } else if (u[i].first == u[j].second || u[i].second == u[j].second) { z = u[j].first; flag = true; } if (flag) { if (((x < y&&x < z) || (x > y&&x > z)) && y != z) { say("YES"); re; } } } say("NO"); }