#include using namespace std; struct Edge { int u, v; }; int n,m; int a[1010]; Edge es[4010]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for (int i = 1; i < n + 1; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; es[i] = Edge({u, v}); } for (int i = 0; i < m; i++) { for (int j = i + 1; j < m; j++) { int x, y, z; x = y = z = 0; if (es[i].u == es[j].u) { x = es[i].v, y = es[i].u, z = es[j].v; } else if (es[i].u == es[j].v) { x = es[i].v, y = es[i].u, z = es[j].u; } else if (es[i].v == es[j].u) { x = es[i].u, y = es[i].v, z = es[j].v; } else if (es[i].v == es[j].v) { x = es[i].u, y = es[i].v, z = es[j].u; } if (x) { // cout << x << ' ' << y << ' ' << z << endl; x = a[x], y = a[y], z = a[z]; if ((x < y && y > z && x != z) || (x > y && y < z && x != z)) { cout << "YES" << endl; return 0; } } } } cout << "NO" << endl; return 0; }