#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 2;
const int M = 1e6;
const int mod = 998244353;
const int inf = 2e9 + 3;
const long long INF = 1e16;
int n, m, down[N], up[N];
long long ans = 1, add[2];
vector<int> lft[N], rht[N];
struct tree {
  int t[5 * M];
  void build(int v = 1, int tl = 0, int tr = M) {
    t[v] = 0;
    if (tl == tr) return;
    int tm = tl + tr >> 1;
    build(v * 2, tl, tm);
    build(v * 2 + 1, tm + 1, tr);
  }
  void upd(int pos, int v = 1, int tl = 0, int tr = M) {
    if (tl == tr) {
      t[v]++;
      return;
    }
    int tm = tl + tr >> 1;
    if (pos <= tm)
      upd(pos, v * 2, tl, tm);
    else
      upd(pos, v * 2 + 1, tm + 1, tr);
    t[v] = t[v * 2] + t[v * 2 + 1];
  }
  int get(int l, int r, int v = 1, int tl = 0, int tr = M) {
    if (l <= tl && tr <= r) return t[v];
    if (tr < l || r < tl) return 0;
    int tm = tl + tr >> 1;
    return get(l, r, v * 2, tl, tm) + get(l, r, v * 2 + 1, tm + 1, tr);
  }
} d, u;
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    int y, xb, xe;
    scanf("%d %d %d", &y, &xb, &xe);
    if (xb == 0) lft[xe].push_back(y);
    if (xe == M && xb != 0) rht[xb].push_back(y);
    if (xb == 0 && xe == M) ans++;
  }
  for (int i = 1; i <= m; ++i) {
    int x, yb, ye;
    scanf("%d %d %d", &x, &yb, &ye);
    if (yb == 0) down[x] = ye;
    if (ye == M && yb != 0) up[x] = yb;
    if (yb == 0 && ye == M) ans++;
  }
  d.build();
  u.build();
  for (int i = 0; i <= M; ++i) {
    if (down[i]) d.upd(down[i]);
    if (up[i]) u.upd(up[i]);
    for (auto it : lft[i]) ans += d.get(it, M) + u.get(0, it);
  }
  d.build();
  u.build();
  for (int i = M; i >= 0; --i) {
    if (down[i]) d.upd(down[i]);
    if (up[i]) u.upd(up[i]);
    for (auto it : rht[i]) ans += d.get(it, M) + u.get(0, it);
  }
  printf("%lld", ans);
}
