class imos2D: def __init__(self, h, w): self.h = h self.w = w self.imos = [[0]*(w+1) for i in range(h+1)] def add(self, y0, x0, y1, x1, v): # add [(y0,x0), (y1,x1)] self.imos[y0][x0] += v self.imos[y1+1][x1+1] += v self.imos[y0][x1+1] -= v self.imos[y1+1][x0] -= v def calc(self): for y in range(self.h+1): for x in range(self.w): self.imos[y][x+1] += self.imos[y][x] for x in range(self.w+1): for y in range(self.h): self.imos[y+1][x] += self.imos[y][x] import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n, k = map(int, input().split()) XY = [] for i in range(n): x, y, h = map(int, input().split()) x += 500 y += 500 XY.append((x, y, h)) imos = imos2D(1550, 1550) for i in range(k): ax, ay, w, h, d = map(int, input().split()) ax += 500 ay += 500 imos.add(ax, ay, ax+w, ay+h, d) imos.calc() ans = 0 for x, y, h in XY: ans += max(0, h-imos.imos[x][y]) print(ans)