#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pr = pair<T, T>;
struct SegTree {
  vector<int> segtree;
  int N;
  SegTree(int n) {
    N = 1;
    while (N < n) N <<= 1;
    segtree = vector<int>(2 * N);
  }
  void increment(int k, int x) {
    k += N;
    if (x == 1)
      ++segtree[k];
    else
      --segtree[k];
    for (k /= 2; k > 0; k /= 2)
      segtree[k] = segtree[k * 2] + segtree[k * 2 + 1];
  }
  long long query(int a, int b) {
    long long ans = 0;
    for (a += N, b += N; a <= b; a /= 2, b /= 2) {
      if (a % 2 == 1) ans += segtree[a++];
      if (b % 2 == 0) ans += segtree[b--];
    }
    return ans;
  }
};
void solve() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<pr<pr<int>>> ev;
  long long ans = 1;
  for (signed i = 0; i < n; ++i) {
    int y, xi, xe;
    cin >> y >> xi >> xe;
    if (xi == 0 and xe == (int)1e6) ++ans;
    ev.push_back(make_pair(make_pair(xi, -1), make_pair(y, 0)));
    ev.push_back(make_pair(make_pair(xe, 1), make_pair(y, 0)));
  }
  for (signed i = 0; i < m; ++i) {
    int x, yi, ye;
    cin >> x >> yi >> ye;
    if (yi == 0 and ye == (int)1e6) ++ans;
    ev.push_back(make_pair(make_pair(x, 0), make_pair(yi, ye)));
  }
  SegTree swp(1e6 + 1);
  sort((ev).begin(), (ev).end());
  for (signed i = 0; i < ev.size(); ++i) {
    if (ev[i].first.second == -1)
      swp.increment(ev[i].second.first, 1);
    else if (ev[i].first.second == 1)
      swp.increment(ev[i].second.first, -1);
    else {
      int x = ev[i].first.first, yi = ev[i].second.first,
          ye = ev[i].second.second;
      ans += swp.query(yi, ye);
    }
  }
  cout << ans << endl;
}
signed main() {
  signed t = 1;
  while (t--) solve();
}
