#include <bits/stdc++.h>
using namespace std;
int N_MAX = 1000100;
int ft[1000200];
void update(int pos, int val) {
  while (pos <= N_MAX) {
    ft[pos] += val;
    pos += (pos & (-pos));
  }
}
int query(int pos) {
  int resp = 0;
  while (pos >= 1) {
    resp += ft[pos];
    pos -= (pos & (-pos));
  }
  return resp;
}
int main() {
  priority_queue<pair<pair<int, int>, pair<int, int> >,
                 vector<pair<pair<int, int>, pair<int, int> > >,
                 greater<pair<pair<int, int>, pair<int, int> > > >
      cola;
  int x, y, a, b;
  int n, m;
  scanf("%d %d", &n, &m);
  long long ans = 1;
  for (int i = 0; i < n; i++) {
    scanf("%d %d %d", &y, &a, &b);
    cola.push({{a, 1}, {y, b}});
    cola.push({{b, 3}, {y, a}});
    if (a == 0 && b == 1000000) ans++;
  }
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d", &x, &a, &b);
    cola.push({{x, 2}, {a, b}});
    if (a == 0 && b == 1000000) ans++;
  }
  long long z1, z2, k;
  pair<pair<int, int>, pair<int, int> > v;
  while (!cola.empty()) {
    v = cola.top();
    cola.pop();
    switch (v.first.second) {
      case 1:
        update(v.second.first, 1);
        break;
      case 2:
        z1 = query(v.second.first - 1);
        z2 = query(v.second.second);
        k = (z2 - z1);
        ans += k;
        break;
      case 3:
        update(v.second.first, -1);
        break;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
