#include <bits/stdc++.h>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
using namespace std;
using ll = long long;
const ll N = 1e6 + 3LL;
const int inf = 1e9 + 3;
const ll M = 1e9 + 7;
const ll T = 998244353;
const double pi = 3.14159;
ll n, m;
ll t[4 * N];
ll xl[N], xr[N];
bool mark[N];
vector<ll> start[N], en[N];
void upd(ll v, ll tl, ll tr, ll pos, ll val) {
  if (tl == tr) {
    t[v] = val;
    return;
  }
  ll tm = (tl + tr) / 2;
  if (pos <= tm) {
    upd(2 * v, tl, tm, pos, val);
  } else {
    upd(2 * v + 1, tm + 1, tr, pos, val);
  }
  t[v] = t[2 * v] + t[2 * v + 1];
}
ll query(ll v, ll tl, ll tr, ll l, ll r) {
  if (l > r) {
    return 0;
  }
  if (tl == l && tr == r) {
    return t[v];
  }
  ll tm = (tl + tr) / 2;
  return query(2 * v, tl, tm, l, min(r, tm)) +
         query(2 * v + 1, tm + 1, tr, max(l, tm + 1), r);
}
void solve() {
  cin >> n >> m;
  ll i, j, w1, w2, p;
  for (i = 0; i <= N - 1; i++) {
    mark[i] = false;
  }
  ll ans = 1;
  for (i = 1; i <= n; i++) {
    cin >> p >> w1 >> w2;
    mark[p] = true;
    xl[p] = w1;
    xr[p] = w2;
    if (w1 == 0 && w2 == 1000000LL) {
      ans++;
    }
  }
  for (i = 1; i <= m; i++) {
    cin >> p >> w1 >> w2;
    start[w1].push_back(p);
    en[w2].push_back(p);
    if (w1 == 0 && w2 == 1000000LL) {
      ans++;
    }
  }
  ll e = 999999LL;
  for (i = 0; i <= 1000000LL; i++) {
    for (auto u : start[i]) {
      upd(1, 1, e, u, 1);
    }
    if (mark[i]) {
      ans += query(1, 1, e, max(xl[i], 1LL), min(xr[i], e));
    }
    for (auto u : en[i]) {
      upd(1, 1, e, u, 0);
    }
  }
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int _t = 1, i;
  for (i = 1; i <= _t; i++) {
    solve();
  }
  return 0;
}
