#include <bits/stdc++.h>
using namespace std;
bool isrange(int second, int first, int n, int m) {
  if (0 <= second && second < n && 0 <= first && first < m) return true;
  return false;
}
int dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1},
    ddy[8] = {1, 0, -1, 0, 1, 1, -1, -1}, ddx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
const int MAX = 1000100;
vector<pair<int, int> > v[MAX];
int seg[MAX * 4], start = 1;
void upd(int wh, int first) {
  wh += start;
  seg[wh] += first;
  for (int e = (wh / 2); e >= 1; e /= 2) seg[e] = seg[e * 2] + seg[e * 2 + 1];
}
int getn(int l, int r) {
  l += start;
  r += start;
  int ans = 0;
  while (l <= r) {
    if (l % 2) {
      ans += seg[l];
      l++;
    }
    if ((r % 2) == 0) {
      ans += seg[r];
      r--;
    }
    l /= 2;
    r /= 2;
  }
  return ans;
}
int main(void) {
  while (start < MAX) start *= 2;
  int n, m;
  scanf("%d%d", &n, &m);
  for (int e = 0; e < n; e++) {
    int second, lx, rx;
    scanf("%d%d%d", &second, &lx, &rx);
    if (lx == 0)
      v[second].push_back(make_pair(1, rx));
    else if (rx == 1e6)
      v[second].push_back(make_pair(2, lx));
  }
  long long int ans = 1;
  for (int e = 0; e < m; e++) {
    int first, ly, ry;
    scanf("%d%d%d", &first, &ly, &ry);
    if (ly == 0 && ry == 1e6) {
      upd(first, 1);
      ans++;
    } else {
      if (ly == 0) v[ry].push_back(make_pair(3, first));
      if (ry == 1e6) {
        v[ly].push_back(make_pair(4, first));
        upd(first, 1);
      }
    }
  }
  upd(1e6, 1);
  for (int e = 1e6; e >= 1; e--) {
    sort(v[e].begin(), v[e].end());
    for (int p = 0; p < (int)v[e].size(); p++) {
      int ty = v[e][p].first;
      int xx = v[e][p].second;
      if (ty == 3) upd(xx, 1);
    }
    for (int p = 0; p < (int)v[e].size(); p++) {
      int ty = v[e][p].first;
      int xx = v[e][p].second;
      if (ty == 4) upd(xx, -1);
      if (ty == 3) continue;
      if (ty == 2) {
        ans += getn(xx, 1e6 - 1);
      }
      if (ty == 1) {
        ans += getn(0, xx);
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
