n,m=map(int,input().split()) p=list(map(int,input().split())) c=[tuple(map(int,input().split())) for i in range(n)] b=[tuple(map(int,input().split())) for i in range(m)] L=7 X=10**(L-1) d={} for fx in [1,-1]: for fy in [1,-1]: for i in range(n): for j in range(m): cx,cy=c[i] bx,by=b[j] v=int(str((bx-cx*fx)+X).zfill(L)+str((by-cy*fy)+X).zfill(L)+str(fx+1).zfill(1)+str(fy+1).zfill(1)) if v not in d: d[v]=0 d[v]+=p[i] print(max([d[v] for v in d]+[0]))