#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(time(nullptr));
const long long INF = 1e18, P = 1e9 + 7, N = 1e5 + 10, M = 1e6;
const long double EPS = 1e-9;
struct Treap {
  int l, r, x, y, sz;
};
vector<Treap> tree;
int root, n, m;
vector<int> add[M + 10], del[M + 10];
vector<pair<int, int> > qr[M + 10];
void push(int t) {
  if (t == 0) {
    return;
  }
  tree[t].sz = tree[tree[t].l].sz + tree[tree[t].r].sz + 1;
}
pair<int, int> split(int t, int k) {
  if (t == 0) {
    return {0, 0};
  }
  if (tree[t].x >= k) {
    pair<int, int> p = split(tree[t].l, k);
    tree[t].l = p.second;
    push(t);
    return {p.first, t};
  }
  pair<int, int> p = split(tree[t].r, k);
  tree[t].r = p.first;
  push(t);
  return {t, p.second};
}
int mrg(int t1, int t2) {
  if (t1 == 0) {
    return t2;
  }
  if (t2 == 0) {
    return t1;
  }
  if (tree[t1].y >= tree[t2].y) {
    tree[t1].r = mrg(tree[t1].r, t2);
    push(t1);
    return t1;
  }
  tree[t2].l = mrg(t1, tree[t2].l);
  push(t2);
  return t2;
}
void add_el(int x) {
  Treap sas;
  sas.y = rnd();
  sas.x = x;
  sas.l = sas.r = 0;
  sas.sz = 1;
  tree.push_back(sas);
  int id = tree.size() - 1;
  pair<int, int> p = split(root, x);
  root = mrg(p.first, mrg(id, p.second));
}
void del_el(int x) {
  pair<int, int> p1 = split(root, x), p2 = split(p1.second, x + 1);
  root = mrg(p1.first, p2.second);
}
int cnt_less(int t, int x) {
  if (t == 0) {
    return 0;
  }
  push(t);
  push(tree[t].l);
  if (tree[t].x > x) {
    return cnt_less(tree[t].l, x);
  } else {
    return cnt_less(tree[t].r, x) + tree[tree[t].l].sz + 1;
  }
}
void build() {
  Treap sas;
  sas.x = sas.l = sas.r = sas.sz = 0;
  sas.y = rnd();
  root = 0;
  tree.push_back(sas);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  long long ans = 1;
  build();
  for (int i = 0; i < n; i++) {
    int y, l, r;
    cin >> y >> l >> r;
    if (l == 0 && r == M) {
      ans++;
    }
    add[l].push_back(y);
    if (r != M) {
      del[r + 1].push_back(y);
    }
  }
  for (int i = 0; i < m; i++) {
    int x, l, r;
    cin >> x >> l >> r;
    if (l == 0 && r == M) {
      ans++;
    }
    qr[x].push_back({l, r});
  }
  int cnt_seg = 0;
  for (int x = 0; x <= M; x++) {
    for (int y : add[x]) {
      add_el(y);
      cnt_seg++;
    }
    for (int y : del[x]) {
      del_el(y);
      cnt_seg--;
    }
    for (pair<int, int> elem : qr[x]) {
      int l = elem.first, r = elem.second;
      if (l == 0) {
        ans += cnt_less(root, r);
      } else {
        ans += cnt_seg - cnt_less(root, l - 1);
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
