#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; long long MOD = 1000000007; bool isKadomatsu( int a, int b, int c ) { return ( a < b && b > c && a != c ) || ( a > b && b < c && a != c ); } int main() { int N,M; cin >> N >> M; vector A(N); for ( int i = 0; i < N; i++ ) { cin >> A[i]; } vector< vector > P( M,vector(2) ); for ( int i = 0; i < M; i++ ) { cin >> P[i][0] >> P[i][1]; P[i][0]--; P[i][1]--; } for ( int i = 0; i < M; i++ ) { for ( int j = i+1; j < M; j++ ) { for ( int a = 0; a < 2; a++ ) { for ( int b = 0; b < 2; b++ ) { if ( P[i][a] == P[j][b] && isKadomatsu( A[P[i][1-a]],A[P[i][a]],A[P[j][1-b]] ) ) { cout << "YES" << endl; return 0; } } } } } cout << "NO" << endl; return 0; }