def f(a,b,p,q,imos): if p > q: return imos[p] += b if p+1 < n: imos[p+1] += a-b y = a*(q-p)+b if q+1 < n: imos[q+1] += -y-a if q+2 < n: imos[q+2] += y import sys readline = sys.stdin.readline n,m = [int(i) for i in readline().split()] a = [int(i) for i in readline().split()] xw = [[int(i) for i in readline().split()] for _ in range(m)] from itertools import accumulate as acc def check(c): imos = [0]*(n) for x,w in xw: x -= 1 v = w//c l = max(0,x-v) f(c,w-c*(x-l),l,x-1,imos) f(-c,w,x,min(n-1,x+v),imos) res = list(acc(acc(imos))) return all(ri < ai for ri,ai in zip(res,a)) ng = V = 0 ok = M = 2**17 if sum(r[1] for r in xw) < min(a): ok = 0 while ok-ng > 1: mid = (ok+ng)//2 if check(mid): ok = mid else: ng = mid if ok < M: print(ok) else: print(-1)