#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long hor[100005];
long long startx[1000005], endx[1000005];
unordered_set<long long> starty[1000005], endy[1000005];
long long tree[1000005];
void add(long long i, long long x) {
  while (i <= 1e6) {
    tree[i] += x;
    i += i & (-i);
  }
}
long long sum(long long i) {
  if (i == -1) {
    return 0;
  }
  long long cnt = 0;
  while (true) {
    cnt += tree[i];
    if (i == 0) {
      break;
    }
    i -= i & (-i);
  }
  return cnt;
}
int main() {
  cin >> n >> m;
  long long ans = 1;
  for (long long i = 0; i < n; ++i) {
    cin >> hor[i];
    cin >> startx[hor[i]] >> endx[hor[i]];
    if (startx[hor[i]] == 0 && endx[hor[i]] == 1000000) {
      ++ans;
    }
  }
  for (long long i = 0; i < m; ++i) {
    long long ver1, starty1, endy1;
    cin >> ver1 >> starty1 >> endy1;
    if (starty1 == 0 && endy1 == 1000000) {
      ++ans;
    }
    starty[starty1].insert(ver1);
    endy[endy1].insert(ver1);
  }
  for (long long i = 0; i <= 1e6; ++i) {
    for (auto x : starty[i]) {
      add(x, 1);
    }
    if (i) {
      for (auto x : endy[i - 1]) {
        add(x, -1);
      }
    }
    if (endx[i] != 0) {
      ans += sum(endx[i]) - sum(startx[i] - 1);
    }
  }
  cout << ans << "\n";
  return 0;
}
