#include <bits/stdc++.h>
using namespace std;
const int maxn = 8e6 + 5;
int c[maxn], n, m, x, y, l, r;
vector<pair<int, int> > _l, _r, _u, _d;
int lowbit(int x) { return x & (-x); }
void update(int x, int v) {
  while (x < maxn) {
    c[x] += v;
    x += lowbit(x);
  }
}
int query(int x) {
  int ret = 0;
  while (x > 0) {
    ret += c[x];
    x -= lowbit(x);
  }
  return ret;
}
int main() {
  cin >> n >> m;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> y >> l >> r;
    if (l == 0) {
      _l.push_back(make_pair(r, y));
      if (r == 1e6) ans++;
    } else
      _r.push_back(make_pair(l, y));
  }
  for (int i = 0; i < m; i++) {
    cin >> x >> l >> r;
    if (l == 0) {
      _u.push_back(make_pair(x, r));
      if (r == 1e6) ans++;
    } else
      _d.push_back(make_pair(x, l));
  }
  sort(_l.begin(), _l.end());
  sort(_r.begin(), _r.end());
  sort(_d.begin(), _d.end());
  sort(_u.begin(), _u.end());
  int ptr_l = 0, ptr_r = 0;
  for (int i = 0; i < _l.size(); i++) update(_l[i].second, 1);
  for (int i = 0; i < _u.size(); i++) {
    while (ptr_l < _l.size() && _l[ptr_l].first < _u[i].first) {
      update(_l[ptr_l].second, -1);
      ptr_l++;
    }
    while (ptr_r < _r.size() && _r[ptr_r].first <= _u[i].first) {
      update(_r[ptr_r].second, 1);
      ptr_r++;
    }
    ans += query(_u[i].second);
  }
  memset(c, 0, sizeof(c));
  ptr_l = 0, ptr_r = 0;
  for (int i = 0; i < _l.size(); i++) update(_l[i].second, 1);
  for (int i = 0; i < _d.size(); i++) {
    while (ptr_l < _l.size() && _l[ptr_l].first < _d[i].first) {
      update(_l[ptr_l].second, -1);
      ptr_l++;
    }
    while (ptr_r < _r.size() && _r[ptr_r].first <= _d[i].first) {
      update(_r[ptr_r].second, 1);
      ptr_r++;
    }
    ans += query(1000000) - query(_d[i].second - 1);
  }
  cout << ans + 1 << endl;
}
