#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int mxn = 1000000;
const int mod = 1e9 + 7;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) f = c == '-' ? -1 : 1, c = getchar();
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  return x * f;
}
inline long long gcd(long long a, long long b) {
  return b == 0 ? a : gcd(b, a % b);
}
long long ksm(long long a, long long b, long long mod) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}
long long inv2(long long a, long long mod) { return ksm(a, mod - 2, mod); }
void exgcd(long long a, long long b, long long &x, long long &y, long long &d) {
  if (!b) {
    d = a;
    x = 1;
    y = 0;
  } else {
    exgcd(b, a % b, y, x, d);
    y -= x * (a / b);
  }
}
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int n, m;
vector<pair<int, int> > a[mxn + 6], b[mxn + 6];
struct BinaryIndexTree {
  long long tr[mxn + 6];
  void add(int x, int v) {
    while (x <= mxn) {
      tr[x] += v;
      x += ((x) & -(x));
    }
  }
  long long sum(int x) {
    long long res = 0;
    while (x) {
      res += tr[x];
      x -= ((x) & -(x));
    }
    return res;
  }
} bit;
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout.tie(0);
  ;
  cin >> n >> m;
  long long res = 1;
  int x, y, lx, ly, rx, ry;
  for (int i = 1; i <= n; ++i) {
    cin >> y >> lx >> rx;
    if (lx == 0 && rx == mxn) res++;
    a[lx].push_back(make_pair(y, 1));
    a[rx + 1].push_back(make_pair(y, -1));
  }
  for (int i = 1; i <= m; ++i) {
    cin >> x >> ly >> ry;
    if (ly == 0 && ry == mxn) res++;
    b[x].push_back(make_pair(ly, ry));
  }
  for (int i = 0; i <= mxn; ++i) {
    for (auto it : a[i]) bit.add(it.first, it.second);
    for (auto it : b[i]) {
      long long uy = bit.sum(it.second);
      long long dy = 0;
      if (it.first) dy = bit.sum(it.first - 1);
      res += uy - dy;
    }
  }
  cout << res << endl;
  return 0;
}
