#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool read(T &x) {
  x = 0;
  register char c = getchar();
  register bool f = 0;
  while (!isdigit(c)) {
    if (c == EOF) return 0;
    f ^= c == '-';
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  if (f) x = -x;
  return 1;
}
template <class T>
inline void print(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) print(x / 10);
  putchar(x % 10 ^ 48);
}
template <class T, class... S>
inline bool read(T &x, S &...y) {
  return read(x) && read(y...);
}
template <class T>
inline void print(T x, char c) {
  print(x);
  putchar(c);
}
struct node1 {
  int y, x, val;
  bool operator<(const node1 &obj) const { return x < obj.x; }
} sx[100005 * 2];
struct node2 {
  int x, l, r;
  bool operator<(const node2 &obj) const { return x < obj.x; }
} sy[100005];
int tr[5000005];
long long ans;
int n, m, x, y, l, r, now;
void update(int now, int l, int r, int x, int val) {
  tr[now] += val;
  if (l == r) return;
  int mid = l + r >> 1;
  if (x <= mid)
    update(now << 1, l, mid, x, val);
  else
    update(now << 1 | 1, mid + 1, r, x, val);
}
int query(int now, int l, int r, int L, int R) {
  if (L <= l && r <= R) return tr[now];
  int mid = l + r >> 1;
  int temp = 0;
  if (L <= mid) temp += query(now << 1, l, mid, L, R);
  if (mid < R) temp += query(now << 1 | 1, mid + 1, r, L, R);
  return temp;
}
int main() {
  read(n, m);
  for (int i = 1; i <= n; i++) {
    read(y, l, r);
    if (l == 0 && r == 1e6) ans++;
    sx[i * 2 - 1] = (node1){y, l, 1};
    sx[i * 2] = (node1){y, r + 1, -1};
  }
  for (int i = 1; i <= m; i++) {
    read(x, l, r);
    if (l == 0 && r == 1e6) ans++;
    sy[i] = (node2){x, l, r};
  }
  sort(sx + 1, sx + 2 * n + 1);
  sort(sy + 1, sy + m + 1);
  for (int i = 1; i <= m; i++) {
    while (now < 2 * n && sx[now + 1].x <= sy[i].x)
      now++, update(1, 1, 1e6, sx[now].y, sx[now].val);
    ans += (long long)query(1, 1, 1e6, sy[i].l, sy[i].r);
  }
  print(ans + 1, '\n');
  return 0;
}
