#include using namespace std; typedef long long ll; ll N,M; ll A[100010] = {},Lsum[100010] = {},Rsum[100010] = {}; ll B[100010] = {}; ll Limos[100010] = {},Rimos[100010] = {}; ll R[100010],S[100010]; bool ok(ll m){ for(int i=0;i<=N+1;i++){ Lsum[i] = 0; Rsum[i] = 0; Limos[i] = 0; Rimos[i] = 0; } for(int i=1;i<=M;i++){ Lsum[R[i]] += S[i]; Rsum[R[i]] += S[i]; if(m!=0){Limos[R[i]+1]++; Limos[min(R[i]+S[i]/m+1,N+1)]--; Lsum[min(R[i]+S[i]/m+1,N+1)] -= S[i]%m;} if(m!=0){Rimos[R[i]-1]++; Rimos[max(R[i]-S[i]/m-1,0LL)]--; Rsum[max(R[i]-S[i]/m-1,0LL)] -= S[i]%m;} } for(int i=1;i<=N;i++){ Limos[i] += Limos[i-1]; Lsum[i] += Lsum[i-1]-m*Limos[i]; } for(int i=N;i>=1;i--){ Rimos[i] += Rimos[i+1]; Rsum[i] += Rsum[i+1]-m*Rimos[i]; } /* cerr << "m:" << m << endl; cerr << "fuan:"; for(int i=1;i<=N;i++) cerr << Rsum[i]+Lsum[i]-B[i] << " "; cerr << endl; cerr << "Limos:"; for(int i=1;i<=N;i++) cerr << Limos[i] << " "; cerr << endl; cerr << "Rimos:"; for(int i=1;i<=N;i++) cerr << Rimos[i] << " "; cerr << endl; */ for(int i=1;i<=N;i++){ if(Rsum[i]+Lsum[i]-B[i]>=A[i]) return false; } return true; } int main(){ cin >> N >> M; for(int i=1;i<=N;i++) cin >> A[i]; for(int i=1;i<=M;i++){ cin >> R[i] >> S[i]; B[R[i]] += S[i]; }ll l = -1,r = 1e9; while(l+1