#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LLINF = 1e18;
const int MAXN = 1e6 + 10;
int n, m;
long long ans = 1;
long long BIT[MAXN];
void updBIT(int p, long long val) {
  p++;
  for (; p < MAXN; p += p & -p) BIT[p] += val;
}
long long sumBIT(int p) {
  p++;
  long long ret = 0;
  for (; p; p -= p & -p) ret += BIT[p];
  return ret;
}
priority_queue<pair<int, pair<int, int>>> sweep;
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    int y, l, r;
    scanf("%d %d %d", &y, &l, &r);
    if (l <= 0 && r >= 1000000) {
      ans++;
    }
    sweep.push({-l, {1e8, y}});
    sweep.push({-r, {-1e8, y}});
  }
  for (int i = 0; i < m; i++) {
    int x, l, r;
    scanf("%d %d %d", &x, &l, &r);
    if (l <= 0 && r >= 1000000) ans++;
    sweep.push({-x, {l, r}});
  }
  while (!sweep.empty()) {
    if (sweep.top().second.first == 1e8) {
      updBIT(sweep.top().second.second, 1);
    } else if (sweep.top().second.first == -1e8) {
      updBIT(sweep.top().second.second, -1);
    } else {
      ans += (sumBIT(sweep.top().second.second) -
              sumBIT(sweep.top().second.first - 1));
    }
    sweep.pop();
  }
  printf("%lld\n", ans);
  return 0;
}
