#include <bits/stdc++.h>
using namespace std;
const int Rea = 1e5 + 3;
struct Rin {
  char c;
  inline char gc() {
    static char rea[Rea];
    static char *head, *tail;
    return head == tail && (tail = (head = rea) + fread(rea, 1, Rea, stdin),
                            head == tail)
               ? EOF
               : *head++;
  }
  inline Rin &operator>>(int &x) {
    bool tag = false;
    x = 0;
    for (c = gc(); c > '9' || c < '0'; c = gc())
      if (c == '-') {
        c = gc();
        tag = true;
        break;
      }
    for (; c >= '0' && c <= '9'; c = gc()) x = (x << 1) + (x << 3) + (c ^ '0');
    if (tag) x = -x;
    return *this;
  }
  inline Rin &operator>>(long long &x) {
    bool tag = false;
    x = 0;
    for (c = gc(); c > '9' || c < '0'; c = gc())
      if (c == '-') {
        c = gc();
        tag = true;
        break;
      }
    for (; c >= '0' && c <= '9'; c = gc()) x = (x << 1) + (x << 3) + (c ^ '0');
    if (tag) x = -x;
    return *this;
  }
} rin;
inline void jh(int &x, int &y) {
  if (x ^ y) x ^= y ^= x ^= y;
  return;
}
inline void jh(long long &x, long long &y) {
  if (x ^ y) x ^= y ^= x ^= y;
  return;
}
inline int min(int x, int y) { return x < y ? x : y; }
inline int max(int x, int y) { return x > y ? x : y; }
inline long long min(long long x, long long y) { return x < y ? x : y; }
inline long long max(long long x, long long y) { return x > y ? x : y; }
const int N = 1e5 + 3;
const int S = 1e6;
int n, m;
struct gyq {
  int x, y;
  gyq(int x_ = 0, int y_ = 0) {
    x = x_;
    y = y_;
  }
};
vector<gyq> U;
vector<gyq> D;
vector<gyq> L;
vector<gyq> R;
vector<int> X;
vector<int> Y;
long long ans;
inline bool myru_y(gyq x, gyq y) { return x.y < y.y; }
inline bool myru_x(gyq x, gyq y) { return x.x < y.x; }
int f[S + 3];
inline int lowbit(int x) { return x & (-x); }
inline void add(int x, int y) {
  for (; x <= S; x += lowbit(x)) f[x] += y;
  return;
}
inline int check(int x) {
  int y = 0;
  for (; x; x -= lowbit(x)) y += f[x];
  return y;
}
int main() {
  rin >> n >> m;
  for (int i = 1, y, l, r; i <= n; i++) {
    rin >> y >> l >> r;
    if (l == 0 && r == S) {
      Y.push_back(y);
      continue;
    }
    if (l == 0) R.push_back(gyq(r, y));
    if (r == S) L.push_back(gyq(l, y));
  }
  for (int i = 1, x, l, r; i <= m; i++) {
    rin >> x >> l >> r;
    if (l == 0 && r == S) {
      X.push_back(x);
      continue;
    }
    if (l == 0) U.push_back(gyq(x, r));
    if (r == S) D.push_back(gyq(x, l));
  }
  ans = 1LL * (X.size() + 1) * (Y.size() + 1);
  sort(X.begin(), X.end());
  sort(Y.begin(), Y.end());
  sort(L.begin(), L.end(), myru_x);
  sort(R.begin(), R.end(), myru_x);
  sort(U.begin(), U.end(), myru_x);
  sort(D.begin(), D.end(), myru_x);
  vector<gyq>::iterator i = R.begin(), u = U.begin(), d = D.begin();
  for (; i != R.end(); i++) {
    for (; u != U.end() && u->x <= i->x; u++) add(1, 1), add(u->y + 1, -1);
    for (; d != D.end() && d->x <= i->x; d++) add(d->y, 1);
    ans += check(i->y) +
           (X.size() - (X.end() - upper_bound(X.begin(), X.end(), i->x)));
  }
  for (; u != U.end(); u++) add(1, 1), add(u->y + 1, -1);
  for (; d != D.end(); d++) add(d->y, 1);
  i = L.begin();
  u = U.begin();
  d = D.begin();
  for (; i != L.end(); i++) {
    for (; u != U.end() && u->x < i->x; u++) add(1, -1), add(u->y + 1, 1);
    for (; d != D.end() && d->x < i->x; d++) add(d->y, -1);
    ans += check(i->y) + (X.end() - lower_bound(X.begin(), X.end(), i->x));
  }
  for (i = U.begin(); i != U.end(); i++)
    ans += (Y.size() - (Y.end() - upper_bound(Y.begin(), Y.end(), i->y)));
  for (i = D.begin(); i != D.end(); i++)
    ans += (Y.end() - lower_bound(Y.begin(), Y.end(), i->y));
  printf("%lld\n", ans);
  return 0;
}
