import sys sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def SI(): return sys.stdin.readline()[:-1] def main(): def ok(c): if c==0: s=sum(w for i,w in xw) for a in aa: if aa:return False return True n,m=MI() aa=LI() xw=LLI(m) l=-1 r=inf=10**9+5 while l+1