#include <bits/stdc++.h>
using namespace std;
struct horiz {
  long long y, x1, x2;
} X[1000010];
struct verti {
  long long x, y1, y2;
} Y[1000010];
vector<pair<long long, long long> > st[1000010], en[1000010];
vector<long long> line[1000010];
set<long long> id;
long long n, m;
bool comp1(const horiz &a, horiz &b) { return a.y < b.y; }
bool comp2(const verti &a, verti &b) { return a.x < b.x; }
long long t[1000010];
void update(long long idx, long long x) {
  while (idx <= 1000000) {
    t[idx] += x;
    idx += (idx & -idx);
  }
}
long long read(long long idx) {
  long long sum = 0ll;
  while (idx > 0ll) {
    sum += t[idx];
    idx -= (idx & -idx);
  }
  return sum;
}
int main() {
  long long i, j, ans = 1ll;
  scanf("%lld %lld", &n, &m);
  for (i = 0; i < n; i++) {
    scanf("%lld %lld %lld", &X[i].y, &X[i].x1, &X[i].x2);
    if (llabs(X[i].x1 - X[i].x2) == 1000000) ans++;
  }
  for (i = 0; i < m; i++) {
    scanf("%lld %lld %lld", &Y[i].x, &Y[i].y1, &Y[i].y2);
    id.insert(Y[i].y1);
    id.insert(Y[i].y2);
    st[Y[i].y1].push_back(pair<long long, long long>(Y[i].x, i));
    en[Y[i].y2].push_back(pair<long long, long long>(Y[i].x, i));
    if (llabs(Y[i].y1 - Y[i].y2) == 1000000) ans++;
  }
  sort(X, X + n, comp1);
  sort(Y, Y + m, comp2);
  for (i = 0; i < n; i++) {
    id.insert(X[i].y);
    line[X[i].y].push_back(i);
  }
  for (auto u : id) {
    long long sz = (long long)st[u].size();
    for (i = 0; i < sz; i++) {
      update(st[u][i].first, 1ll);
    }
    sz = (long long)line[u].size();
    for (i = 0; i < sz; i++) {
      long long v = line[u][i];
      ans += read(X[v].x2) - read(X[v].x1 - 1);
    }
    sz = (long long)en[u].size();
    for (i = 0; i < sz; i++) {
      update(en[u][i].first, -1ll);
    }
  }
  printf("%lld\n", ans);
  return 0;
}
