#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10;
long long INF = 1e9 + 10;
long long MOD = 1000000007;
int LEN = 1e6;
int n, m;
pair<int, pair<int, int> > h[MAXN];
vector<pair<int, int> > v_up, v_down;
int fen[MAXN];
void upd(int pos, int val) {
  while (pos < MAXN) {
    fen[pos] += val;
    pos |= (pos + 1);
  }
}
int get(int pos) {
  int res = 0;
  while (pos >= 0) {
    res += fen[pos];
    pos = (pos & (pos + 1)) - 1;
  }
  return res;
}
int calc_for_pos(pair<int, int> pos) {
  int res = 0;
  if (pos.first == 0)
    res += get(pos.second);
  else
    res += get(LEN - 1) - get(pos.first - 1);
  return res;
}
long long calc_up() {
  v_up.push_back({LEN, LEN});
  sort(v_up.begin(), v_up.end());
  for (auto it : v_up) upd(it.second, 1);
  sort(h, h + n);
  h[n] = {LEN, {0, LEN}};
  long long res = 0;
  for (int i = 0, j = 0; i <= n; i++) {
    while (j < v_up.size() && v_up[j].first < h[i].first) {
      upd(v_up[j].second, -1);
      j++;
    }
    res += calc_for_pos(h[i].second);
  }
  return res;
}
long long calc_down() {
  fill(fen, fen + MAXN, 0);
  sort(v_down.begin(), v_down.end());
  reverse(v_down.begin(), v_down.end());
  for (auto it : v_down) upd(it.second, 1);
  reverse(h, h + n);
  long long res = 0;
  for (int i = 0, j = 0; i < n; i++) {
    while (j < v_down.size() && v_down[j].first > h[i].first) {
      upd(v_down[j].second, -1);
      j++;
    }
    res += calc_for_pos(h[i].second);
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    cin >> h[i].first >> h[i].second.first >> h[i].second.second;
  for (int i = 0; i < m; i++) {
    int x, l_y, r_y;
    cin >> x >> l_y >> r_y;
    if (l_y == 0)
      v_up.push_back({r_y, x});
    else
      v_down.push_back({l_y, x});
  }
  long long res = calc_up();
  res += calc_down();
  cout << res << endl;
  return 0;
}
