#include "bits/stdc++.h" using namespace std; #define ll long long int #define rep(i,n) for( int i = 0; i < n; i++ ) #define rrep(i,n) for( int i = n; i >= 0; i-- ) #define REP(i,s,t) for( int i = s; i <= t; i++ ) #define RREP(i,s,t) for( int i = s; i >= t; i-- ) #define dump(x) cerr << #x << " = " << (x) << endl; #define INF 2000000000 #define mod 1000000007 #define INF2 1000000000000000000 vector> V; vector G[2010]; int a[2010]; void dfs(vector v, int parent, int depth, int x) { v.push_back(a[x]); if (depth == 0) { V.push_back(v); return; } rep(i, G[x].size()) { if (G[x][i] != parent) { dfs(v, x, depth - 1, G[x][i]); } } } int main(void) { cin.tie(0); ios::sync_with_stdio(false); int N, M; cin >> N >> M; rep(i, N) cin >> a[i + 1]; rep(i, M) { int a, b; cin >> a >> b; G[a].push_back(b); G[b].push_back(a); } rep(i, N) { vector k; dfs(k, -1, 2, i + 1); } rep(i, V.size()) { //cout << V[i][0] << " " << V[i][1] << " " << V[i][2] << endl; if (V[i][0] != V[i][2] && (V[i][0] < V[i][1] && V[i][2] < V[i][1] || V[i][0] > V[i][1] && V[i][2] > V[i][1])) { cout << "YES" << endl; return 0; } } cout << "NO" << endl; return 0; }