#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
int n;
int m;
int t[4 * N];
void upd(int l, int r, int v = 1, int tl = 1, int tr = N) {
  if (l > r) return;
  if (l <= tl && tr <= r) {
    t[v]++;
    return;
  }
  int tm = (tl + tr) / 2;
  upd(l, min(tm, r), v * 2, tl, tm);
  upd(max(tm + 1, l), r, v * 2 + 1, tm + 1, tr);
}
int get(int pos, int v = 1, int tl = 1, int tr = N) {
  if (tl == tr) return t[v];
  int tm = (tl + tr) / 2;
  if (pos <= tm)
    return t[v] + get(pos, v * 2, tl, tm);
  else
    return t[v] + get(pos, v * 2 + 1, tm + 1, tr);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  long long res = 1;
  vector<pair<int, int>> left;
  vector<pair<int, int>> right;
  for (int i = 1; i <= n; i++) {
    int y, l, r;
    cin >> y >> l >> r;
    if (l == 0 && r == N) res++;
    if (l == 0)
      left.push_back({y, r});
    else
      right.push_back({y, l});
  }
  sort(left.begin(), left.end());
  sort(right.begin(), right.end());
  vector<pair<int, int>> top;
  vector<pair<int, int>> bottom;
  for (int i = 1; i <= m; i++) {
    int x, l, r;
    cin >> x >> l >> r;
    if (l == 0 && r == N) res++;
    if (l == 0)
      bottom.push_back({r, x});
    else
      top.push_back({l, x});
  }
  sort(bottom.begin(), bottom.end());
  int i1 = 0, i2 = 0;
  for (int i = 0; i < (int)bottom.size(); i++) {
    while (i1 < (int)left.size() && left[i1].first <= bottom[i].first) {
      upd(0, left[i1].second);
      i1++;
    }
    while (i2 < (int)right.size() && right[i2].first <= bottom[i].first) {
      upd(right[i2].second, N);
      i2++;
    }
    res += get(bottom[i].second);
  }
  memset(t, 0, sizeof t);
  sort(top.rbegin(), top.rend());
  reverse(left.begin(), left.end());
  reverse(right.begin(), right.end());
  i1 = 0, i2 = 0;
  for (int i = 0; i < (int)top.size(); i++) {
    while (i1 < (int)left.size() && left[i1].first >= top[i].first) {
      upd(0, left[i1].second);
      i1++;
    }
    while (i2 < (int)right.size() && right[i2].first >= top[i].first) {
      upd(right[i2].second, N);
      i2++;
    }
    res += get(top[i].second);
  }
  cout << res << "\n";
}
