#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int n, m;
  long long ans = 1;
  cin >> n >> m;
  vector<vector<int>> v(1000005);
  vector<int> h(1000005, 0), bit(1000005, 0);
  for (int i = 0; i < n; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    if (b == 0 && c == 1000000) ++ans;
    v[b].push_back(a), v[c + 1].push_back(-a);
  }
  for (int i = 0; i < m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    if (b == 0 && c == 1000000) ++ans;
    if (b)
      h[a] = -b;
    else
      h[a] = c;
  }
  for (int i = 0; i < 1000000; ++i) {
    for (int j : v[i]) {
      if (j > 0)
        for (; j < 1000005; j += j & -j) ++bit[j];
      else
        for (j *= -1; j < 1000005; j += j & -j) --bit[j];
    }
    if (h[i] > 0)
      for (int j = h[i]; j; j -= j & -j) ans += bit[j];
    else if (h[i] < 0) {
      for (int j = 1000004; j; j -= j & -j) ans += bit[j];
      for (int j = -h[i] - 1; j; j -= j & -j) ans -= bit[j];
    }
  }
  cout << ans;
}
