#include <bits/stdc++.h>
using namespace std;
vector<long long> v1[1000005], v0[1000005];
vector<pair<long long, long long> > v[1000005];
long long seg[4000005];
void update1(long long v, long long l, long long r, long long x) {
  seg[v]++;
  if (l == r) {
    return;
  }
  long long mid = (l + r) / 2;
  if ((x >= l) && (x <= mid)) {
    update1(2 * v, l, mid, x);
  } else {
    update1(2 * v + 1, mid + 1, r, x);
  }
}
void update2(long long v, long long l, long long r, long long x) {
  seg[v]--;
  if (l == r) {
    return;
  }
  long long mid = (l + r) / 2;
  if ((x >= l) && (x <= mid)) {
    update2(2 * v, l, mid, x);
  } else {
    update2(2 * v + 1, mid + 1, r, x);
  }
}
long long query(long long v, long long tl, long long tr, long long l,
                long long r) {
  if (l > r) {
    return 0;
  }
  if ((l == tl) && (r == tr)) {
    return seg[v];
  }
  long long mid = (tl + tr) / 2;
  long long temp1 = query(2 * v, tl, mid, l, min(mid, r));
  long long temp2 = query(2 * v + 1, mid + 1, tr, max(l, mid + 1), r);
  return (temp1 + temp2);
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long n, m;
  cin >> n >> m;
  v1[0].push_back(0);
  v1[0].push_back(1000000);
  long long ctr = 0;
  for (long long i = 1; i <= n; i++) {
    long long y, lx, rx;
    cin >> y >> lx >> rx;
    v1[lx].push_back(y);
    v0[rx].push_back(y);
    if ((rx == 1000000) && (lx != 0)) {
      ctr++;
    }
  }
  vector<pair<long long, pair<long long, long long> > > num;
  for (long long i = 1; i <= m; i++) {
    long long x, ly, ry;
    cin >> x >> ly >> ry;
    v[x].push_back({ly, ry});
  }
  v[1000000].push_back({0, 1000000});
  long long res = 0;
  for (long long i = 0; i <= 1000000; i++) {
    for (long long j = 0; j < v1[i].size(); j++) {
      update1(1, 0, 1000000, v1[i][j]);
    }
    for (long long j = 0; j < v[i].size(); j++) {
      res += query(1, 0, 1000000, v[i][j].first, v[i][j].second) - 1;
    }
    for (long long j = 0; j < v0[i].size(); j++) {
      update2(1, 0, 1000000, v0[i][j]);
    }
  }
  cout << res - ctr << "\n";
}
