#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 5;
struct BIT {
  long long data[N];
  void modify(long long pos, long long val) {
    while (pos < N) {
      data[pos] += val;
      pos += pos & (-pos);
    }
  }
  long long sum(long long pos) {
    long long res = 0;
    for (; pos > 0; pos -= pos & (-pos)) {
      res += data[pos];
    }
    return res;
  }
  long long query(long long l, long long r) {
    return sum(r) - sum(max((long long)0, l - 1));
  }
} bit;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  long long ans = 1;
  vector<array<long long, 3>> v;
  for (long long i = 0; i < n; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    if (c - b == (long long)1e6) ans++;
    v.push_back({b, a, 1});
    v.push_back({c + 1, a, -1});
  }
  for (long long i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    if (c - b == (long long)1e6) ans++;
    v.push_back({a, b, c + 2});
  }
  sort(v.begin(), v.end(), [&](array<long long, 3> a, array<long long, 3> b) {
    if (a[0] != b[0]) return a[0] < b[0];
    return a[2] < b[2];
  });
  bool checked = false;
  for (auto x : v) {
    if (x[2] > 1) {
      ans += bit.query(x[1], x[2] - 2);
    } else {
      bit.modify(x[1], x[2]);
    }
  }
  cout << ans << "\n";
}
