#include<bits/stdc++.h> usingnamespace std; #define ll long long constint INF = 0x3f3f3f3f; const ll inf = 0x3f3f3f3f3f3f3f3f; constint N = 2e6 + 10; const ll mod = 1e9 + 7; int n, m, M = 1000000; ll ans = 1ll; structX { int lx, rx, y; booloperator<(const X& b)const { return y < b.y; } }a[N]; //横 structQ { int y, tp, x; booloperator<(const Q& b)const { return y == b.y ? tp < b.tp : y < b.y; } }; int ad[]{ 1,-1 }; vector<Q>vc; int sum[N]; intlowbit(int x){ return x & -x; } voidadd(int p, int x){ for (int i = p; i <= M; i += lowbit(i)) { sum[i] += x; } } intqry(int r){ int res = 0; for (int i = r; i > 0; i -= lowbit(i)) { res += sum[i]; } return res; } intmain(){ scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d%d%d", &a[i].y, &a[i].lx, &a[i].rx); if (a[i].lx == 0 && a[i].rx == M)ans++; } sort(a + 1, a + n + 1); for (int i = 1; i <= m; i++) { int ly, ry, x; scanf("%d%d%d", &x, &ly, &ry); if (ly == 0 && ry == M)ans++; vc.push_back(Q{ ly,0,x }); vc.push_back(Q{ ry,1,x }); } sort(vc.begin(), vc.end()); m = (int)vc.size(); int nw = 0; for (int i = 1; i <= n; i++) { while (nw < m && (vc[nw].y < a[i].y || vc[nw].y == a[i].y&&vc[nw].tp == 0)) { add(vc[nw].x, ad[vc[nw].tp]); nw++; } ans += qry(a[i].rx) - qry(a[i].lx - 1); } printf("%lld\n", ans); return0; }