#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  lint n, m;
  cin >> n >> m;
  vector<lint> a(n), b(n), c(n);
  vector<lint> d(m), e(m), f(m);
  map<lint, lint> xs, ys;
  set<lint> usedx, usedy;
  usedx.insert(-1000000010);
  usedx.insert(0);
  usedx.insert(1000000010);
  usedy.insert(-1000000010);
  usedy.insert(0);
  usedy.insert(1000000010);
  xs[-1000000010] = 0;
  xs[0] = 0;
  xs[1000000010] = 0;
  ys[-1000000010] = 0;
  ys[0] = 0;
  ys[1000000010] = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i] >> c[i];
    xs[a[i]] = 0;
    xs[b[i]] = 0;
    ys[c[i]] = 0;
    usedx.insert(a[i]);
    usedx.insert(b[i]);
    usedy.insert(c[i]);
  }
  for (int i = 0; i < m; ++i) {
    cin >> d[i] >> e[i] >> f[i];
    xs[d[i]] = 0;
    ys[e[i]] = 0;
    ys[f[i]] = 0;
    usedx.insert(d[i]);
    usedy.insert(e[i]);
    usedy.insert(f[i]);
  }
  int xidx = 0;
  for (auto &p : xs) {
    p.second = xidx++;
  }
  int yidx = 0;
  for (auto &p : ys) {
    p.second = yidx++;
  }
  vector<vector<lint>> area(xidx, vector<lint>(yidx, 0));
  for (auto itx = next(usedx.begin()); itx != prev(usedx.end());
       itx = next(itx)) {
    for (auto ity = next(usedy.begin()); ity != prev(usedy.end());
         ity = next(ity)) {
      int ix = xs[*itx], iy = ys[*ity];
      area[ix][iy] = (*next(itx) - *itx) * (*next(ity) - *ity);
    }
  }
  map<pair<pair<int, int>, int>, bool> blc;
  for (int i = 0; i < n; ++i) {
    for (int j = xs[a[i]]; j < xs[b[i]]; ++j) {
      int y = ys[c[i]];
      blc[{{j, y - 1}, 0}] = true;
      blc[{{j, y}, 1}] = true;
    }
  }
  for (int i = 0; i < m; ++i) {
    for (int j = ys[e[i]]; j < ys[f[i]]; ++j) {
      int x = xs[d[i]];
      blc[{{x, j}, 2}] = true;
      blc[{{x - 1, j}, 3}] = true;
    }
  }
  vector<vector<lint>> visited(xidx, vector<lint>(yidx, 0));
  queue<pair<int, int>> q;
  q.push({xs[0], ys[0]});
  visited[xs[0]][ys[0]] = 1;
  lint ret = area[xs[0]][ys[0]];
  while (!q.empty()) {
    auto p = q.front();
    q.pop();
    if (!blc[{p, 0}] && visited[p.first][p.second + 1] == 0) {
      if (p.second == yidx - 3) {
        cout << "INF"
             << "\n";
        return 0;
      }
      ret += area[p.first][p.second + 1];
      visited[p.first][p.second + 1] = 1;
      q.push({p.first, p.second + 1});
    }
    if (!blc[{p, 1}] && visited[p.first][p.second - 1] == 0) {
      if (p.second == 1) {
        cout << "INF"
             << "\n";
        return 0;
      }
      ret += area[p.first][p.second - 1];
      visited[p.first][p.second - 1] = 1;
      q.push({p.first, p.second - 1});
    }
    if (!blc[{p, 2}] && visited[p.first - 1][p.second] == 0) {
      if (p.first == 1) {
        cout << "INF"
             << "\n";
        return 0;
      }
      ret += area[p.first - 1][p.second];
      visited[p.first - 1][p.second] = 1;
      q.push({p.first - 1, p.second});
    }
    if (!blc[{p, 3}] && visited[p.first + 1][p.second] == 0) {
      if (p.first == xidx - 3) {
        cout << "INF"
             << "\n";
        return 0;
      }
      ret += area[p.first + 1][p.second];
      visited[p.first + 1][p.second] = 1;
      q.push({p.first + 1, p.second});
    }
  }
  cout << ret << "\n";
  return 0;
}
