#include <bits/stdc++.h>
using namespace std;
int n, m;
map<int, pair<vector<int>, vector<pair<int, int> > > > sweep;
int bit[1000010];
void upd(int c, int v) {
  int i = c;
  while (i < 1000010) {
    bit[i] += v;
    i += (i & (-i));
  }
}
int query(int c) {
  int i = c, res = 0;
  while (i > 0) {
    res += bit[i];
    i -= (i & (-i));
  }
  return res;
}
int main() {
  scanf(" %d%d", &n, &m);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int y, l, r;
    scanf(" %d%d%d", &y, &l, &r);
    sweep[l].first.push_back(y);
    sweep[r].first.push_back(-y);
    if (l == 0 && r == 1000000) ans++;
  }
  for (int i = 0; i < m; i++) {
    int x, b, t;
    scanf(" %d%d%d", &x, &b, &t);
    sweep[x].second.push_back(make_pair(b, t));
    if (b == 0 && t == 1000000) ans++;
  }
  memset(bit, 0, sizeof(bit));
  for (auto i : sweep) {
    for (int j : i.second.first)
      if (j > 0) upd(j, 1);
    for (auto j : i.second.second) ans += query(j.second) - query(j.first - 1);
    for (int j : i.second.first)
      if (j < 0) upd(-j, -1);
  }
  printf("%lld\n", ans + 1);
}
