#include <bits/stdc++.h>
using namespace std;
struct Merge {
  set<vector<long long int>> lr;
  long long int INF = 1000000000000000009;
  vector<long long int> remove(long long int a, long long int b) {
    if (a > b) swap(a, b);
    auto itr = lr.lower_bound(vector<long long int>{b + 1, 0});
    if (itr == lr.begin()) return vector<long long int>{a, b};
    itr--;
    long long int lef = a, ri = b;
    while ((*itr)[1] >= a) {
      long long int now_x = (*itr)[0], now_y = (*itr)[1];
      lef = min(lef, now_x), ri = max(ri, now_y);
      if (itr == lr.begin()) {
        lr.erase(itr);
        break;
      }
      itr--;
      lr.erase(vector<long long int>{now_x, now_y});
    }
    return vector<long long int>{lef, ri};
  }
  void merge(long long int a, long long int b) { lr.insert(remove(a, b)); }
  vector<long long int> get(long long int a) {
    auto itr = lr.lower_bound(vector<long long int>{a + 1, a + 1});
    if (lr.size() == 0 || itr == lr.begin())
      return vector<long long int>{INF, INF};
    itr--;
    if ((*itr)[1] < a) return vector<long long int>{INF, INF};
    return *itr;
  }
  bool same(long long int a, long long int b) {
    if (get(a)[0] == -1) return false;
    if (get(a)[0] == INF) return false;
    return get(a)[0] == get(b)[0];
  }
};
long long int MAX = 1000000;
void err() {
  std::cout << "INF" << '\n';
  exit(0);
}
int main(int argc, char const *argv[]) {
  int n, m;
  std::cin >> n >> m;
  vector<vector<int>> X = vector<vector<int>>(n, vector<int>(3, 0));
  vector<vector<int>> Y = vector<vector<int>>(m, vector<int>(3, 0));
  map<long long int, long long int> mp, rev;
  for (int i = 0; i < n; i++) {
    scanf("%d %d %d", &X[i][0], &X[i][1], &X[i][2]);
    mp.emplace(X[i][0], 0);
    mp.emplace(X[i][1], 0);
    mp.emplace(X[i][2], 0);
  }
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d", &Y[i][0], &Y[i][1], &Y[i][2]);
    mp.emplace(Y[i][0], 0);
    mp.emplace(Y[i][1], 0);
    mp.emplace(Y[i][2], 0);
  }
  mp.emplace(0, 0);
  long long int c = 0;
  for (auto itr = mp.begin(); itr != mp.end(); itr++, c++) (*itr).second = c;
  for (auto v : mp) rev.emplace(v.second, v.first);
  vector<Merge> sakux(mp.size());
  vector<Merge> sakuy(mp.size());
  for (auto v : X) {
    long long int a = mp.at(v[0]);
    long long int b = mp.at(v[1]);
    long long int c = mp.at(v[2]);
    sakux[c].merge(a, b);
  }
  for (auto v : Y) {
    long long int a = mp.at(v[0]);
    long long int b = mp.at(v[1]);
    long long int c = mp.at(v[2]);
    sakuy[a].merge(b, c);
  }
  vector<vector<bool>> l(mp.size() + 10, vector<bool>(mp.size() + 10, 0));
  vector<vector<bool>> ar(mp.size() + 10, vector<bool>(mp.size() + 10, 0));
  long long int ans = 0;
  long long int z = mp.at(0);
  queue<pair<pair<int, int>, pair<int, int>>> q;
  q.push(pair<pair<int, int>, pair<int, int>>(pair<int, int>(z, z),
                                              pair<int, int>(MAX, MAX)));
  int dx[4] = {1, 1, -1, -1};
  int dy[4] = {-1, 1, -1, 1};
  ar[z][z] = 1;
  std::cout << "---" << '\n';
  while (!q.empty()) {
    pair<pair<int, int>, pair<int, int>> top = q.front();
    q.pop();
    int x = top.first.first, y = top.first.second;
    pair<int, int> pre = top.second;
    for (int i = 0; i < 4; i++) {
      if (x + dx[i] == pre.first && y + dy[i] == pre.second) continue;
      if (pre.first != MAX && sakux[y].same(x, x + 1) &&
          sakux[y].same(x, x - 1)) {
        long long int tmp = y - pre.second;
        if (tmp * dy[i] > 0) continue;
      }
      if (pre.first != MAX && sakuy[x].same(y, y + 1) &&
          sakuy[x].same(y, y - 1)) {
        long long int tmp = x - pre.first;
        if (tmp * dx[i] > 0) continue;
      }
      if (i == 0) {
        if (sakux[y].same(x, x + 1) && sakuy[x].same(y, y - 1)) continue;
        if (sakux[y].same(x, x - 1) && sakuy[x].same(y, y + 1)) continue;
      }
      if (i == 1) {
        if (sakux[y].same(x, x + 1) && sakuy[x].same(y, y + 1)) continue;
        if (sakux[y].same(x, x - 1) && sakuy[x].same(y, y - 1)) continue;
      }
      if (i == 2) {
        if (sakux[y].same(x, x + 1) && sakuy[x].same(y, y + 1)) continue;
        if (sakux[y].same(x, x - 1) && sakuy[x].same(y, y - 1)) continue;
      }
      if (i == 3) {
        if (sakux[y].same(x, x + 1) && sakuy[x].same(y, y - 1)) continue;
        if (sakux[y].same(x, x - 1) && sakuy[x].same(y, y + 1)) continue;
      }
      if (x + dx[i] < 0 || x + dx[i] >= mp.size() || y + dy[i] < 0 ||
          y + dy[i] >= mp.size()) {
        err();
      }
      long long int minx = min(x, x + dx[i]);
      long long int miny = min(y, y + dy[i]);
      if (!l[minx][miny]) {
        l[minx][miny] = 1;
        long long int DX = abs(rev.at(x + dx[i]) - rev.at(x));
        long long int DY = abs(rev.at(y + dy[i]) - rev.at(y));
        ans += DX * DY;
      }
      if (!ar[x + dx[i]][y + dy[i]]) {
        ar[x + dx[i]][y + dy[i]] = 1;
        q.push(pair<pair<int, int>, pair<int, int>>(
            pair<int, int>(x + dx[i], y + dy[i]), pair<int, int>(x, y)));
      }
    }
  }
  exit(1);
  std::cout << ans << '\n';
  return 0;
}
