#include using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define llong long long bool isKadomatsu(int x, int y, int z) { if(x == y || y == z || z == x) return false; return (x > y && z > y) || (x < y && z < y) ; } int main() { int n, m; cin >> n >> m; vector vals(n); rep(i, n) cin >> vals[i]; vector> graph(n); rep(i, m) { int a, b; cin >> a >> b; graph[a-1].push_back(b-1); graph[b-1].push_back(a-1); } rep(xi, n) { int x = vals[xi]; for(int yi: graph[xi]) { if(xi == yi) continue; int y = vals[yi]; for(int zi: graph[yi]) { if(zi == yi || zi == xi) continue; int z = vals[zi]; if(isKadomatsu(x, y, z)) { cout << "YES\n"; return 0; } } } } cout << "NO\n"; }