#include <bits/stdc++.h>
using namespace std;
const int M = 15, N = 25;
int n, m, mv[M], s[N], t[N], c[N], a[M], b[M], p[M], ad[105];
int ans = 0x3f3f3f3f;
void dfs (int idx, int ss) {
if (ss >= ans) return;
if (idx > m) {
for (int i = 1;i <= n;i++) {
for (int j = s[i];j <= t[i];j++) if (ad[j] < c[i]) return;
}
ans = min(ans, ss);
}
dfs(idx+1, ss);
for (int i = a[idx];i <= b[idx];i++) ad[i] += p[idx];
dfs(idx+1, ss+mv[idx]);
for (int i = a[idx];i <= b[idx];i++) ad[i] -= p[idx];
}
int main () {
freopen("kongtiao.in", "r", stdin);
freopen("kongtiao.out", "w", stdout);
cin >> n >> m;
for (int i = 1;i <= n;i++) cin >> s[i] >> t[i] >> c[i];
for (int i = 1;i <= m;i++) cin >> a[i] >> b[i] >> p[i] >> mv[i];
dfs(1, 0);
cout << ans << endl;
// system("pause");
return 0;
}