#include <bits/stdc++.h>
using namespace std;
const int MX = 1e6;
int n, m;
vector<pair<int, int>> ranges[MX + 10];
int bit[MX + 10];
void upd(int ind, int val) {
  while (ind <= MX) {
    bit[ind] += val;
    ind += (ind & -ind);
  }
}
int qry(int ind) {
  int ans = 0;
  while (ind > 0) {
    ans += bit[ind];
    ind -= (ind & -ind);
  }
  return ans;
}
int main() {
  cin >> n >> m;
  set<vector<int>> points;
  long long ans = 1;
  for (int i = 0; i < n; i++) {
    int y, l, r;
    cin >> y >> l >> r;
    if (l == 0 && r == MX) ans++;
    points.insert({l, y, 1});
    points.insert({r + 1, y, -1});
  }
  for (int i = 0; i < m; i++) {
    int x, l, r;
    cin >> x >> l >> r;
    if (l == 0 && r == MX) ans++;
    ranges[x].push_back(make_pair(l, r));
  }
  for (int i = 0; i < MX; i++) {
    if (points.size() > 0) {
      vector<int> first = *points.begin();
      while (first[0] == i) {
        upd(first[1], first[2]);
        points.erase(first);
        if (points.size() == 0) break;
        first = *points.begin();
      }
    }
    for (pair<int, int> range : ranges[i]) {
      ans += (qry(range.second) - qry(range.first - 1));
    }
  }
  cout << ans;
}
