#include using namespace std; long long bit[2020][2020]; void update(int y, int x, long long v) { for (int i = y; i < 2020; i += i & -i) { for (int j = x; j < 2020; j += j & -j) { bit[i][j] += v; } } } long long query(int y, int x) { long long result = 0; for (int i = y; i > 0; i -= i & -i) { for (int j = x; j > 0; j -= j & -j) { result += bit[i][j]; } } return result; } int main() { int n, k; cin >> n >> k; const int offset = 510; vector xs(n); vector ys(n); vector hp(n); for (int i = 0; i < n; i++) { scanf("%d %d %d", &xs[i], &ys[i], &hp[i]); xs[i] += offset; ys[i] += offset; } for (int i = 0; i < k; i++) { int x, y, w, h, d; scanf("%d %d %d %d %d", &x, &y, &w, &h, &d); x += offset; y += offset; update(y, x, d); update(y + h + 1, x, -d); update(y, x + w + 1, -d); update(y + h + 1, x + w + 1, d); } long long ans = 0; for (int i = 0; i < n; i++) { ans += max(0ll, hp[i] - query(ys[i], xs[i])); } cout << ans << endl; }