#include <bits/stdc++.h>
using namespace std;
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
const long long mod = 1e9 + 7;
long long add(long long x, long long y) { return (1ll * x + 1ll * y) % mod; }
long long mul(long long x, long long y) { return (1ll * x * 1ll * y) % mod; }
long long del(long long x, long long y) {
  return ((1ll * x - 1ll * y) % mod + mod) % mod;
}
long long binpow(long long x, long long m) {
  if (m == 0) return 1;
  if (m == 1)
    return x;
  else {
    long long sum = binpow(x, m / 2);
    sum = mul(sum, sum);
    if (m % 2) sum = mul(sum, x);
    return sum;
  }
}
bool checkBit(long long x, long long pos) {
  if ((x & (1 << pos)))
    return 1;
  else
    return 0;
}
long long setBit(long long x, long long pos) { return (x | (1 << pos)); }
long long unsetBit(long long x, long long pos) { return (x ^ (1 << pos)); }
const long long N = 2e6 + 5;
const long long inf = 1e6;
long long h, v, doubleX, doubleY;
long long bit[N];
void update(long long x, long long val) {
  while (x < N) {
    bit[x] += val;
    x += x & (-x);
  }
}
long long get(long long x) {
  long long ans = 0;
  while (x > 0) {
    ans += bit[x];
    x -= x & (-x);
  }
  return ans;
}
vector<pair<pair<long long, long long>, pair<long long, long long> > > seg;
void KanekiKen() {
  doubleX = doubleY = 0;
  seg.clear();
  cin >> h >> v;
  for (long long i = 1; i <= h; i++) {
    long long y, lx, rx;
    cin >> y >> lx >> rx;
    if (lx == 0 && rx == inf) doubleY++;
    seg.push_back(make_pair(make_pair(y, 2), make_pair(lx, rx)));
  }
  for (long long i = 1; i <= v; i++) {
    long long x, ly, ry;
    cin >> x >> ly >> ry;
    if (ly == 0 && ry == inf) doubleX++;
    seg.push_back(make_pair(make_pair(max(ly, 1ll), 1ll), make_pair(x, x)));
    seg.push_back(make_pair(make_pair(ry + 1ll, -1ll), make_pair(x, x)));
  }
  long long tot = doubleX + 1 + doubleY;
  sort(seg.begin(), seg.end());
  for (long long i = 0; i < static_cast<long long>((seg).size()); i++) {
    if (seg[i].first.second == 1 || seg[i].first.second == -1)
      update(seg[i].second.first, seg[i].first.second);
    else {
      tot += 1ll * get(seg[i].second.second);
      tot -= 1ll * get(seg[i].second.first - 1);
    }
  }
  cout << tot << "\n";
}
signed main() {
  cin.tie(0), ios_base::sync_with_stdio(0);
  KanekiKen();
}
