#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long
#define ld long double
#define en exit(0);
#define pb push_back
#define fi first
#define se second
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e6 + 5;
const ll INF = 1e18 + 5;
ll A[N], S[N], P[N], B[N], T[N], Q[N];
int n, m;
ll go(int i, int j, ll ctime) // we have taken i IOI Donburis and j JOI Currys
{
// we have reached the end
if(i > n && j > m)
return 0;
ll best = -INF;
if(i <= n) // take i
{
ll nwtime = ctime + A[i];
ll pl = (nwtime <= S[i] ? 1 : 0);
best = max(best, pl + go(i + 1, j, nwtime));
}
if(j <= m)
{
ll nwtime = ctime + B[j];
ll pl = (nwtime <= T[j] ? 1 : 0);
best = max(best, pl + go(i, j + 1, nwtime));
}
return best;
}
int main()
{
fio
// ifstream cin("in.in");
cin >> n >> m;
for(int i = 1;i <= n;i++)
cin >> A[i] >> S[i] >> P[i];
for(int i = 1;i <= m;i++)
cin >> B[i] >> T[i] >> Q[i];
cout << go(1, 1, 0);
return 0;
}