#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1000005;
struct Seg {
  int x, y;
  int k;
  bool operator<(const Seg& rhs) const { return x < rhs.x; }
} seg[2 * N];
struct V {
  int x, y1, y2;
  bool operator<(const V& rhs) const { return x < rhs.x; }
} vlines[N];
ll c[N];
int lowbit(int x) { return x & (-x); }
void modify(int x, int d) {
  for (int i = x; i < N; i += lowbit(i)) c[i] += d;
}
ll query(int x) {
  ll res = 0;
  for (int i = x; i; i -= lowbit(i)) res += c[i];
  return res;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  const int p = 1e6;
  ll res = 0;
  int num = 0;
  int y, l, r;
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d%d", &y, &l, &r);
    if (l == 0 && r == p) ++res;
    l++;
    r++;
    y++;
    seg[++num] = {l, y, 1};
    seg[++num] = {r + 1, y, -1};
  }
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%d", &vlines[i].x, &vlines[i].y1, &vlines[i].y2);
    if (vlines[i].y1 == 0 && vlines[i].y2 == p) ++res;
    vlines[i].y1++;
    vlines[i].y2++;
    vlines[i].x++;
  }
  sort(seg + 1, seg + num + 1);
  sort(vlines + 1, vlines + m + 1);
  for (int i = 1, j = 0; i <= m; ++i) {
    while (j < num && seg[j + 1].x <= vlines[i].x) {
      ++j;
      modify(seg[j].y, seg[j].k);
    }
    res += query(vlines[i].y2) - query(vlines[i].y1 - 1);
  }
  printf("%lld\n", res + 1);
  return 0;
}
