#include <bits/stdc++.h>
using namespace std;
long long int bit[1000009];
void update(long long int x, long long int value) {
  for (; x <= 1000005; x += x & -x) bit[x] += value;
}
long long int query(long long int x) {
  long long int sum = 0;
  for (; x > 0; x -= x & -x) sum += bit[x];
  return sum;
}
multiset<pair<long long int, pair<long long int, long long int>>> s;
void solve() {
  long long int n, m;
  cin >> n >> m;
  long long int x, y, z;
  long long int ans = 0;
  for (long long int i = 0; i < n; i++) {
    cin >> x >> y >> z;
    if (y == 0 && z == 1000000) ans++;
    if (y == 0) {
      update(x, 1);
      s.insert({z, {100000000000000007, -x}});
    } else {
      s.insert({y, {-100000000000000007, x}});
    }
  }
  for (long long int i = 0; i < m; i++) {
    cin >> x >> y >> z;
    if (y == 0 && z == 1000000) ans++;
    s.insert({x, {y, z}});
  }
  for (auto i : s) {
    if (abs(i.second.first) == 100000000000000007)
      update(abs(i.second.second), i.second.second / abs(i.second.second));
    else {
      ans += query(i.second.second);
      ans -= query(i.second.first - 1);
    }
  }
  cout << ans + 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int begtime = clock();
  long long int t = 1;
  for (long long int i = 0; i < t; i++) {
    solve();
  }
  int endtime = clock();
  cerr << "\n\n"
       << "Time elapsed: " << (endtime - begtime) * 1000 / CLOCKS_PER_SEC
       << " ms\n\n";
  return 0;
}
