#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::string;
using std::vector;
struct BIT {
  vector<int64_t> cnt;
  BIT() {}
  BIT(int n) : cnt(n + 1) {}
  void add(int pos, int64_t val) {
    for (++pos; pos < cnt.size(); pos += pos & -pos) cnt[pos] += val;
  }
  int64_t query(int pos) {
    int64_t res = 0;
    for (++pos; pos > 0; pos -= pos & -pos) res += cnt[pos];
    return res;
  }
};
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, m;
  int64_t ans = 1;
  cin >> n >> m;
  using seg = std::tuple<int, int, int>;
  vector<seg> horizon(n);
  for (int i = 0, u, v, w; i < n; ++i) {
    cin >> u >> v >> w;
    ans += (w - v == 1e6);
    horizon[i] = {u, v, w};
  }
  std::sort(horizon.begin(), horizon.end());
  using node = std::tuple<int, int, int>;
  vector<node> nodes;
  for (int i = 0, u, v, w; i < m; ++i) {
    cin >> u >> v >> w;
    ans += (w - v == 1e6);
    nodes.emplace_back(v, u, 1);
    nodes.emplace_back(w + 1, u, -1);
  }
  std::sort(nodes.begin(), nodes.end());
  const int MAXN = 1e6 + 5;
  BIT bit(MAXN);
  int pos = 0;
  for (auto e : horizon) {
    for (; pos < 2 * m; ++pos) {
      if (std::get<0>(nodes[pos]) <= std::get<0>(e))
        bit.add(std::get<1>(nodes[pos]), std::get<2>(nodes[pos]));
      else
        break;
    }
    ans += bit.query(std::get<2>(e)) - bit.query(std::get<1>(e) - 1);
  }
  cout << ans << '\n';
}
