#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10;
const int MAXM = 2e6 + 10;
const long long MOD = 1e9 + 7;
const long long INF = 0x3f3f3f3f;
const unsigned long long BASE = 233;
const int base = 5;
char rubbish[110];
bool GETDATA;
inline long long read() {
  long long x = 0, f = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = -1;
  } while (ch < '0' || ch > '9');
  do {
    x = x * 10 + ch - 48;
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return x * f;
}
inline void write(long long x, char con = '\n') {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10, 0);
  putchar(x % 10 + '0');
  if (con) {
    printf("%c", con);
  }
}
struct Node {
  long long xy;
  long long l, r;
} h[MAXN], v[MAXN];
long long N, M, K;
long long a[MAXN];
long long seg[MAXN << 2];
long long lz[MAXN << 2];
bool cmp1(Node a, Node b) { return a.xy < b.xy; }
bool cmp2(Node a, Node b) {
  if (a.l == b.l) {
    return a.r < b.r;
  }
  return a.l < b.l;
}
void pushdown(int o) {
  if (lz[o]) {
    seg[(o << 1)] += lz[o];
    lz[(o << 1)] += lz[o];
    seg[(o << 1 | 1)] += lz[o];
    lz[(o << 1 | 1)] += lz[o];
    lz[o] = 0;
  }
}
void pushup(int o) { seg[o] = seg[(o << 1)] + seg[(o << 1 | 1)]; }
void build(int o, int l, int r) {
  seg[o] = 0;
  if (l == r) {
    return;
  }
  int m = l + r >> 1;
  build((o << 1), l, m);
  build((o << 1 | 1), m + 1, r);
}
void updata(int o, int l, int r, int x, int y, long long val) {
  if (x <= l && r <= y) {
    seg[o] += val;
    lz[o] += val;
    return;
  }
  int m = l + r >> 1;
  pushdown(o);
  if (m >= x) {
    updata((o << 1), l, m, x, y, val);
  }
  if (m < y) {
    updata((o << 1 | 1), m + 1, r, x, y, val);
  }
  pushup(o);
}
long long query(int o, int l, int r, int x) {
  if (l == r) {
    return seg[o];
  }
  int m = l + r >> 1;
  pushdown(o);
  return x <= m ? query((o << 1), l, m, x) : query((o << 1 | 1), m + 1, r, x);
}
void init() { build(1, 1, 1e6); }
void solve() {
  long long ans = 0;
  int l, r;
  N = read();
  M = read();
  init();
  for (int i = 1; i <= N; i++) {
    h[i].xy = read();
    h[i].l = read();
    h[i].r = read();
    if (h[i].r - h[i].l == 1e6) {
      ans++;
    }
  }
  for (int i = 1; i <= M; i++) {
    v[i].xy = read();
    v[i].l = read();
    v[i].r = read();
    if (v[i].r - v[i].l == 1e6) {
      ans++;
    }
  }
  sort(h + 1, h + 1 + N, cmp1);
  sort(v + 1, v + 1 + M, cmp2);
  l = r = 1;
  for (int i = 1; i <= M; i++) {
    while (r <= N && h[r].xy <= v[i].r) {
      updata(1, 1, 1e6, h[r].l, h[r].r, 1);
      r++;
    }
    while (l < r && h[l].xy < v[i].l) {
      updata(1, 1, 1e6, h[l].l, h[l].r, -1);
      l++;
    }
    ans += query(1, 1, 1e6, v[i].xy);
  }
  write(ans + 1);
}
int main() {
  int T;
  T = 1;
  for (int t = 1; t <= T; t++) {
    GETDATA = false;
    solve();
  }
  return 0;
}
