#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 9, Mod = 1e9 + 7;
int n, m, A[N], Y[N], LX[N], RX[N], F[N];
int X[N], LY[N], RY[N];
vector<int> L[N], R[N], Q[N];
void Add(int i, int val) {
  for (i++; i < N; i += i & -i) F[i] += val;
}
int Get(int i) {
  int rt = 0;
  for (i++; i; i -= i & -i) rt += F[i];
  return rt;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  long long Cnt = 1;
  for (int i = 1; i <= n; i++) {
    cin >> Y[i] >> LX[i] >> RX[i];
    if (LX[i] == 0 && RX[i] == (int)(1e6)) Cnt++;
    L[LX[i]].push_back(i);
    R[RX[i] + 1].push_back(i);
  }
  for (int i = 1; i <= m; i++) {
    cin >> X[i] >> LY[i] >> RY[i];
    if (LY[i] == 0 && RY[i] == (int)(1e6)) Cnt++;
    Q[X[i]].push_back(i);
  }
  for (int i = 0; i <= (int)(1e6); i++) {
    for (int j : L[i]) Add(Y[j], 1);
    for (int j : R[i]) Add(Y[j], -1);
    for (int j : Q[i]) {
      if (LY[j] == 0)
        Cnt += Get(RY[j]);
      else
        Cnt += Get((int)(1e6)) - Get(LY[j] - 1);
    }
  }
  cout << Cnt << endl;
  return 0;
}
