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 g=0 for fx in [1,-1]: for fy in [1,-1]: d={} 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 if v not in d: d[v]=0 d[v]+=p[i] g=max(g,max(d[v] for v in d)) print(g)