n,k = map(int,input().split()) A1 = [list(map(str,input().split())) for _ in range(n)] A = [[0]*n for _ in range(n)] for _ in range(k): Ax,Ay,W,H,D = map(int,input().split()) for i in range(Ax,Ax+W+1): for j in range(Ay,Ay+H+1): A[i][j] += D A2 = A1-A sum = 0 for i in range(n): for j in range(n): if A2[i][j] > 0: sum += A2[i][j] print(sum)