#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;
const int maxN = 1000000;
vector<pair<int, int> > horizontal[maxN + 500], vertical[maxN + 500];
long long int sum[maxN + 500];
void update(int pos, int val) {
  while (pos <= maxN) {
    sum[pos] += val;
    pos += (pos & -pos);
  }
}
long long int getsum(int pos) {
  long long int res = 0;
  while (pos > 0) {
    res += sum[pos];
    pos -= (pos & -pos);
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  long long int ans = 1;
  for (int i = 1; i <= n; i++) {
    int y, l, r;
    cin >> y >> l >> r;
    horizontal[l].push_back({y, 1});
    horizontal[r + 1].push_back({y, -1});
    if (l == 0 and r == 1000000) ans++;
  }
  for (int i = 1; i <= m; i++) {
    int x, l, r;
    cin >> x >> l >> r;
    vertical[x].push_back({l, r});
    if (l == 0 and r == 1000000) ans++;
  }
  for (int i = 0; i <= maxN; i++) {
    for (auto it : horizontal[i]) update(it.first, it.second);
    for (auto it : vertical[i]) ans += getsum(it.second) - getsum(it.first - 1);
  }
  cout << ans;
}
