#include <bits/stdc++.h>
int _w;
FILE* _f;
using namespace std;
const int N = 1e5 + 5;
int n, m, cntx, cnty;
long long ans = 1;
struct bwt {
  int siz = 1 << 20;
  int num[(1 << 20) + 1] = {};
  void add(int u, int d) {
    while (u <= siz) {
      num[u] += d;
      u += u & -u;
    }
  }
  int sum(int u) {
    int tmp = 0;
    while (u > 0) {
      tmp += num[u];
      u -= u & -u;
    }
    return tmp;
  }
  int sum(int l, int r) { return sum(r) - sum(l - 1); }
} sz;
struct nx {
  int tim, pos, val;
  nx(int rt = 0, int rp = 0, int rv = 0) {
    tim = rt;
    pos = rp;
    val = rv;
  }
  bool operator<(const nx& rhs) const { return tim < rhs.tim; }
} x[N << 1];
struct ny {
  int pos, st, en;
  ny(int rp = 0, int rs = 0, int re = 0) {
    pos = rp;
    st = rs;
    en = re;
  }
  bool operator<(const ny& rhs) const { return pos < rhs.pos; }
} y[N];
int main() {
  _w = scanf("%d%d", &n, &m);
  int pos = 0, st = 0, en = 0;
  for (int i = 1; i <= n; i++) {
    _w = scanf("%d%d%d", &pos, &st, &en);
    if (st == 0 && en == (int)1e6) ++ans;
    ++pos;
    ++st;
    ++en;
    x[++cntx] = nx(st, pos, 1);
    x[++cntx] = nx(en + 1, pos, -1);
  }
  x[++cntx] = nx(10 * N - 1, 0, 0);
  sort(x + 1, x + cntx + 1);
  for (int i = 1; i <= m; i++) {
    _w = scanf("%d%d%d", &pos, &st, &en);
    if (st == 0 && en == (int)1e6) ++ans;
    ++pos;
    ++st;
    ++en;
    y[++cnty] = ny(pos, st, en);
  }
  sort(y + 1, y + cnty + 1);
  int itex = 1, itey = 1;
  while (itey <= cnty) {
    while (x[itex].tim <= y[itey].pos) {
      sz.add(x[itex].pos, x[itex].val);
      ++itex;
    }
    ans += sz.sum(y[itey].st, y[itey].en);
    ++itey;
  }
  printf("%lld\n", ans);
  return 0;
}
