def Bisect_Int(ok,ng,is_ok):
while abs(ok-ng)>1:
mid=(ok+ng)//2
if is_ok(mid):
ok=mid
else:
ng=mid
return ok
N,M=map(int,input().split())
A=list(map(int,input().split()))
X,W=[],[]
for m in range(M):
x,w=map(int,input().split())
x-=1
X.append(x)
W.append(w)
def is_ok(c):
if c==0:
sum_W=sum(W)
return all(sum_W=0:
imos[x-w//c]+=w%c
imos[x-w//c+1]-=w%c
imos[x-w//c+1]+=c
imos[x+1]-=c
imos[x+1]+=-w
imos[x+2]-=-w
else:
imos[0]+=w-x*c
imos[1]-=w-x*c
imos[1]+=c
imos[x+1]-=c
imos[x+1]+=-w
imos[x+2]-=-w
for _ in range(2):
for i in range(1,N+2):
imos[i]+=imos[i-1]
return imos[:N]
L=make_weight(X,W)
R=make_weight([N-1-x for x in X],W)[::-1]
LR=[l+r for l,r in zip(L,R)]
for x,w in zip(X,W):
LR[x]-=w
return all(w