#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 1.1e6;
int n, m, t[N], ans;
vector<pii> vc[N], vq[N];
ll p, e;
void insx(int lx, int rx, int y) {
  vc[lx].push_back({y + 1, 1});
  vc[rx + 1].push_back({y + 1, -1});
}
void insy(int ly, int ry, int x) { vq[x].push_back({ly + 1, ry + 1}); }
void change(int pos, int val) {
  for (; pos < N; pos += pos & (-pos)) t[pos] += val;
}
int ask(int pos) {
  int ans = 0;
  for (; pos; pos -= pos & (-pos)) ans += t[pos];
  return ans;
}
signed main() {
  scanf("%d%d", &n, &m);
  insx(0, 1e6, 0), insx(0, 1e6, 1e6);
  insy(0, 1e6, 0), insy(0, 1e6, 1e6);
  for (int i = 1, lx, rx, y; i <= n; ++i) {
    scanf("%d%d%d", &y, &lx, &rx);
    insx(lx, rx, y);
  }
  for (int i = 1, ly, ry, x; i <= m; ++i) {
    scanf("%d%d%d", &x, &ly, &ry);
    insy(ly, ry, x);
  }
  p = (n + m + 4) * 2;
  e = n + m + 4;
  for (int i = 0; i < N; ++i) {
    for (auto j : vc[i]) change(j.first, j.second);
    for (auto j : vq[i]) {
      int val = ask(j.second) - ask(j.first - 1);
      p += val, e += val * 2;
    }
  }
  printf("%lld\n", e - p + 1);
}
