#include using namespace std; using i64 = int64_t; using vi = vector; using vvi = vector; int main() { int n, k; cin >> n >> k; vvi b(1010, vi(1010)); for (int i = 0; i < n; i++) { int x, y, h; cin >> x >> y >> h; x += 500; y += 500; b[x][y] += h; b[x + 1][y] -= h; b[x][y + 1] -= h; b[x + 1][y + 1] += h; } for (int i = 0; i < k; i++) { int x, y, h, w, d; cin >> x >> y >> h >> w >> d; x += 500; y += 500; b[x][y] -= d; if (x + h + 1 < 1010) { b[x + h + 1][y] += d; } if (y + w + 1 < 1010) { b[x][y + w + 1] += d; } if (x + h + 1 < 1010 && y + w + 1 < 1010) { b[x + h + 1][y + w + 1] -= d; } } for (int i = 0; i < 1010; i++) { for (int j = 0; j < 1010 - 1; j++) { b[i][j + 1] += b[i][j]; } } for (int i = 0; i < 1010 - 1; i++) { for (int j = 0; j < 1010; j++) { b[i + 1][j] += b[i][j]; } } i64 cnt = 0; for (int i = 0; i < 1010; i++) { for (int j = 0; j < 1010; j++) { if (b[i][j] > 0) { cnt += b[i][j]; } } } cout << cnt << endl; }