#include <bits/stdc++.h>
using namespace std;
char p[30] = {'0', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
              'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
              'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
inline long long rd() {
  long long x = 0, flag = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch ^ 48);
    ch = getchar();
  }
  return x * flag;
}
int n, m, y[1000010], lx[1000010], rx[1000010], x[1000010], ly[1000010],
    ry[1000010], co[1000010];
long long ans;
inline int lowbit(int x) { return x & (-x); }
inline void add(int x, int v) {
  for (register int i = x; i <= 1e6; i += lowbit(i)) co[i] += v;
}
inline int sum(int x) {
  int ans = 0;
  for (register int i = x; i > 0; i -= lowbit(i)) ans += co[i];
  return ans;
}
vector<int> a[1000010];
vector<int> b[1000010];
vector<int> c[1000010];
int main() {
  std::ios::sync_with_stdio(false);
  n = rd(), m = rd();
  for (register int i = 1; i <= n; ++i) {
    y[i] = rd(), lx[i] = rd(), rx[i] = rd();
    if (rx[i] - lx[i] == 1000000) ans++;
    a[lx[i]].push_back(i);
    b[rx[i] + 1].push_back(i);
  }
  for (register int i = 1; i <= m; ++i) {
    x[i] = rd(), ly[i] = rd(), ry[i] = rd();
    if (ry[i] - ly[i] == 1000000) ans++;
    c[x[i]].push_back(i);
  }
  for (register int i = 0; i <= 1000000; ++i) {
    int siz = a[i].size();
    for (register int j = 0; j < siz; ++j) add(y[a[i][j]], 1);
    siz = b[i].size();
    for (register int j = 0; j < siz; ++j) add(y[b[i][j]], -1);
    siz = c[i].size();
    for (register int j = 0; j < siz; ++j) {
      if (ly[c[i][j]] == 0)
        ans += sum(ry[c[i][j]]);
      else
        ans += sum(1000000) - sum(ly[c[i][j]] - 1);
    }
  }
  cout << ans + 1;
  return 0;
}
