s=[[0]*2000for _ in[0]*2000] f=lambda:map(int,input().split()) n,k=f() E=[f()for _ in[0]*n] for _ in[0]*k: x,y,w,h,d=f() for k in[0,5,9,14]:s[x+k%-3*~w][y+k%-5*~h]+=d*(-1)**k for _ in'!!': for t in(s:=[*map(list,zip(*s))]): for j in range(-500,500):t[j+1]+=t[j] print(sum(max(h-s[x][y],0)for x,y,h in E))