#include <bits/stdc++.h>
using namespace std;
int inline read() {
  int ans = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    ans = ans * 10 + ch - '0';
    ch = getchar();
  }
  return ans * f;
}
const int N = 1e6 + 5, M = 1e5 + 5, lim = 1e6;
int c[N];
int lowbit(int x) { return x & (-x); }
void add(int x, int v) {
  for (int i = x; i <= lim; i += lowbit(i)) c[i] += v;
}
int ask(int x) {
  int ans = 0;
  while (x > 0) {
    ans += c[x];
    x -= lowbit(x);
  }
  return ans;
}
vector<int> st[N], en[N], v[N];
int x[N], y[N], lx[N], ly[N], rx[N], ry[N];
int n, m;
long long ans = 1;
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; i++) {
    y[i] = read();
    lx[i] = read();
    rx[i] = read();
    if (rx[i] - lx[i] == lim) ans++;
    st[lx[i]].push_back(i);
    en[rx[i] + 1].push_back(i);
  }
  for (int i = 1; i <= m; i++) {
    x[i] = read();
    ly[i] = read();
    ry[i] = read();
    if (ry[i] - ly[i] == lim) ans++;
    v[x[i]].push_back(i);
  }
  for (int i = 0; i <= lim; i++) {
    for (int j = 0; j < st[i].size(); j++) add(y[st[i][j]], 1);
    for (int j = 0; j < en[i].size(); j++) add(y[en[i][j]], -1);
    for (int j = 0; j < v[i].size(); j++) {
      if (ly[v[i][j]] == 0)
        ans += ask(ry[v[i][j]]);
      else
        ans += ask(lim) - ask(ly[v[i][j]] - 1);
    }
  }
  cout << ans;
  return 0;
}
