#include using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) begin(v),end(v) template inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } using ll = long long; using pii = pair; constexpr ll INF = 1ll<<30; constexpr ll longINF = 1ll<<60; constexpr ll MOD = 1000000007; constexpr bool debug = false; //---------------------------------// int main() { int N, M; cin >> N >> M; vector A(N); REP(i, N) scanf("%d", &A[i]); vector U(M), V(M); REP(i, M) scanf("%d %d", &U[i], &V[i]), --U[i], --V[i]; puts([&]() -> bool { vector mn(M, INF), mx(M, -INF); REP(i, M) { const int u = U[i], v = V[i]; if (A[u] < A[v]) { if (mx[u] == -INF) mx[u] = A[v]; else if (mx[u] != A[v]) return true; if (mn[v] == INF) mn[v] = A[u]; else if (mn[v] != A[u]) return true; } if (A[u] > A[v]) { if (mn[u] == INF) mn[u] = A[v]; else if (mn[u] != A[v]) return true; if (mx[v] == -INF) mx[v] = A[u]; else if (mx[v] != A[u]) return true; } } return false; }() ? "YES": "NO"); }