#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18 + 1e17;
const long long mod = 1e9 + 7;
using cd = complex<double>;
long long modInverse(long long a, long long m) {
  long long m0 = m;
  long long y = 0, x = 1;
  if (m == 1) return 0;
  while (a > 1) {
    long long q = a / m;
    long long t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += m0;
  return x;
}
long long powm(long long a, long long b) {
  a = a % mod;
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return (res % mod);
}
const long long N = 1e6 + 5;
int arr[4 * N];
struct st {
  int a, b, c, d;
};
void update(int n, int st, int et, int p) {
  if (st > p || et < p) return;
  if (st == et) {
    arr[n] = 1 - arr[n];
    return;
  }
  update(n * 2, st, (st + et) / 2, p);
  update(n * 2 + 1, (st + et) / 2 + 1, et, p);
  arr[n] = arr[n * 2] + arr[n * 2 + 1];
}
long long query(int n, int st, int et, int l, int r) {
  if (st > r || et < l) return 0;
  if (st >= l && et <= r) return arr[n];
  return query(n * 2, st, (st + et) / 2, l, r) +
         query(n * 2 + 1, (st + et) / 2 + 1, et, l, r);
}
bool comp(st x, st y) {
  if (x.a == y.a) return x.d > y.d;
  return x.a < y.a;
}
void solve() {
  int n, m;
  cin >> n >> m;
  vector<st> va;
  vector<pair<long long, long long> > vb;
  memset(arr, 0, sizeof(arr));
  int aa, bb, cc;
  int cnt = 1;
  for (int i = 0; i < n; i++) {
    cin >> aa >> bb >> cc;
    va.push_back({aa, bb, cc, 0});
    if (bb == 0 && cc == 1e6) cnt++;
  }
  for (int i = 0; i < m; i++) {
    int aa, bb, cc;
    cin >> aa >> bb >> cc;
    if (bb == 0 && cc == 1e6) cnt++;
    va.push_back({bb, aa, 0, 1});
    va.push_back({cc + 1, aa, 0, 1});
  }
  sort(va.begin(), va.end(), comp);
  long long ans = 0;
  for (int i = 0; i < va.size(); i++) {
    if (va[i].d == 0) {
      int x = query(1, 0, 1e6, va[i].b, va[i].c);
      ans += x;
    } else {
      update(1, 0, 1e6, va[i].b);
    }
  }
  cout << ans + cnt << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  for (long long i = 1; i <= t; i++) {
    solve();
  }
}
