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=10 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=0 v+=(bx-cx*fx)+10**L v*=10**(L+1) v+=(by-cy*fy)+10**L v*=2 v+=fx+1 v*=2 v+=fy+1 if v not in d: d[v]=0 d[v]+=p[i] print(max([d[v] for v in d]+[0]))