#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using P = pair; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; template inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N, M; cin >> N >> M; vector B(N); for(int i = 0; i < N; ++i) cin >> B[i]; vector> sections(N + 1); for(int i = 0; i < M; ++i){ int L, R; cin >> L >> R; sections[L - 1].emplace(R); } vector rights(N, -1); for(int l = 0; l < N; ++l){ if(sections[l].size() == 0) continue; int r = *sections[l].begin(); rights[l] = r; sections[l].erase(sections[l].begin()); if(sections[l].size() > sections[r + 1].size()){ swap(sections[l], sections[r + 1]); } for(auto it = sections[l].begin(); it != sections[l].end(); ){ sections[r + 1].emplace(*it); it = sections[l].erase(it); } } vector finish(N + 1); ll sum = 0; for(int l = 0; l < N; ++l){ sum -= finish[l]; B[l] -= sum; if(rights[l] != -1){ sum += B[l]; if((rights[l] - l) % 2 == 0) finish[rights[l]] += B[l]; else finish[rights[l]] -= B[l]; B[l] = 0; } sum *= -1; } for(int i = 0; i < N; ++i){ if(B[i] != 0){ cout << "NO\n"; return 0; } } cout << "YES\n"; return 0; }