#include <bits/stdc++.h>
using namespace std;
const int LIM = 1e6;
const int MAX = 1e5 + 10;
struct event {
  long long a, b, c;
};
bool cmp(event e1, event e2) {
  if (e1.a != e2.a) return e1.a < e2.a;
  if (e1.b != e2.b) return e1.b < e2.b;
  return e1.c < e2.c;
}
template <class T>
struct SegTree {
  const T ID = 0;
  int n;
  vector<T> seg;
  T comb(T a, T b) { return a + b; }
  SegTree(int _n) {
    n = _n;
    seg.assign(2 * n, ID);
  }
  void pull(int p) { seg[p] = comb(seg[2 * p], seg[2 * p + 1]); }
  void update(int idx, T val) {
    seg[idx += n] += val;
    for (idx /= 2; idx; idx /= 2) pull(idx);
  }
  T query(int l, int r) {
    T lnode = ID, rnode = ID;
    for (l += n, r += n + 1; l < r; l /= 2, r /= 2) {
      if (l & 1) lnode = comb(lnode, seg[l++]);
      if (r & 1) rnode = comb(seg[--r], rnode);
    }
    return comb(lnode, rnode);
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  SegTree<int> seg(LIM + 10);
  vector<event> events;
  long long ans = 1;
  for (int i = 0; i < n; i++) {
    int y, l, r;
    cin >> y >> l >> r;
    events.push_back({l, -1, y});
    events.push_back({r, LIM + 1, y});
    if (l == 0 && r == LIM) ans++;
  }
  for (int i = 0; i < m; i++) {
    int x, l, r;
    cin >> x >> l >> r;
    events.push_back({x, l, r});
    if (l == 0 && r == LIM) ans++;
  }
  sort(events.begin(), events.end(), cmp);
  for (event e : events) {
    if (e.b == -1)
      seg.update(e.c, 1);
    else if (e.b == LIM + 1)
      seg.update(e.c, -1);
    else
      ans += seg.query(e.b, e.c);
  }
  cout << ans;
  return 0;
}
