#include using namespace std; typedef long long ll; const int INF = 1e9; const int MOD = 1e9+7; int main(void) { int N,K; cin >> N >> K; vector> enemys(1510,vector(1510)); vector> area(1510,vector(1510)); const int GETA = 500; for(int i=0;i> x >> y >> hp; enemys[y+GETA][x+GETA] += hp; } for(int i=0;i> x >> y >> w >> h >> d; y += GETA; x += GETA; area[y][x] += d; area[y+h+1][x+w+1] += d; area[y+h+1][x] -= d; area[y][x+w+1] -= d; } for(int i=0;i<1510;i++){ for(int j=0;j<1510-1;j++){ area[i][j+1] += area[i][j]; } } for(int i=0;i<1510;i++){ for(int j=0;j<1510-1;j++){ area[j+1][i] += area[j][i]; } } ll ret = 0; for(int i=0;i<1510;i++){ for(int j=0;j<1510;j++){ ret += max(0LL,enemys[i][j] - area[i][j]); } } cout << ret << endl; return 0; }