#include <bits/stdc++.h>
using namespace std;
int read() {
  int w = 0, flg = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') flg = -1;
    ch = getchar();
  }
  while (ch <= '9' && ch >= '0') {
    w = w * 10 - '0' + ch, ch = getchar();
  }
  return w * flg;
}
struct line {
  bool pd;
  int h;
  int f;
  int ud;
  int xl, xr;
} l[100010 * 3];
bool cmp(line x, line y) {
  if (x.h < y.h) return true;
  if (x.h > y.h) return false;
  return x.ud > y.ud;
}
int n, m, h1, h2, p1, p2, x[100010];
long long ans = 1;
long long t[100010];
int lowbit(int x) { return x & (-x); }
long long query(int x) {
  int re = 0;
  for (int i = x; i; i -= lowbit(i)) {
    re += t[i];
  }
  return re;
}
void update(int x, int d) {
  for (int i = x; i <= m; i += lowbit(i)) {
    t[i] += d;
  }
}
int main() {
  n = read(), m = read();
  for (int i = (1); i <= (n); i++) {
    h1 = read(), p1 = read(), p2 = read();
    l[i] = (line){1, h1, 0, 0, p1, p2};
    if (p1 == 0 && p2 == 1000000) ans++;
  }
  for (int i = (1); i <= (m); i++) {
    p1 = read(), h1 = read(), h2 = read();
    if (h1 == 0) {
      l[n + (i << 1) - 1] = (line){0, h1, 1, -1, p1, p1};
      l[n + (i << 1)] = (line){0, h2, -1, -1, p1, p1};
    } else {
      l[n + (i << 1) - 1] = (line){0, h1, 1, 1, p1, p1};
      l[n + (i << 1)] = (line){0, h2, -1, 1, p1, p1};
    }
    if (h1 == 0 && h2 == 1000000) ans++;
    x[i] = p1;
  }
  sort(l + 1, l + n + 2 * m + 1, cmp);
  sort(x + 1, x + m + 1);
  for (int i = (1); i <= (n + 2 * m); i++) {
    if (!l[i].pd) {
      int pos = lower_bound(x + 1, x + m + 1, l[i].xl) - x;
      update(pos, l[i].f);
    } else {
      int lll, rr;
      if (l[i].xl == 0)
        lll = 1, rr = upper_bound(x + 1, x + m + 1, l[i].xr) - x - 1;
      else
        rr = m, lll = lower_bound(x + 1, x + m + 1, l[i].xl) - x;
      ans += query(rr) - query(lll - 1);
    }
  }
  printf("%lld\n", ans);
  return 0;
}
