#include <bits/stdc++.h>
using namespace std;
const int N = 6010, oo = -2;
long long n, m, h[N][4], v[N][4], g[N][N], cntRws, cntCls, bIdx, eIdx, yIdx,
    xIdx, res;
bool vst[N][N], rchInf;
set<long long> xSt, ySt;
set<long long>::iterator it;
vector<long long> x, y;
long long clcArea(int i, int j) {
  long long dx, dy;
  if (i % 2 == 0 || j % 2 == 0)
    return 0;
  else if (i == 1 || i == cntRws || j == 1 || j == cntCls)
    return oo;
  dx = x[((j + 1) / 2) - 1] - x[((j - 1) / 2) - 1];
  dy = y[((i + 1) / 2) - 1] - y[((i - 1) / 2) - 1];
  return dx * dy;
}
bool vld(int i, int j) {
  return (i >= 1 && i <= cntRws && j >= 1 && j <= cntCls && !vst[i][j] &&
          g[i][j] != -1);
}
void runDfs(int i, int j) {
  if (vld(i, j)) {
    vst[i][j] = true;
    if (g[i][j] == oo) rchInf = true;
    res += g[i][j];
    runDfs(i, j - 1);
    runDfs(i, j + 1);
    runDfs(i - 1, j);
    runDfs(i + 1, j);
  }
}
void solve() {
  cin >> n >> m;
  xSt.insert(0);
  ySt.insert(0);
  for (int i = 1; i <= n; i++) {
    cin >> h[i][0] >> h[i][1] >> h[i][2];
    xSt.insert(h[i][0]);
    xSt.insert(h[i][1]);
    ySt.insert(h[i][2]);
  }
  for (int i = 1; i <= m; i++) {
    cin >> v[i][0] >> v[i][1] >> v[i][2];
    xSt.insert(v[i][0]);
    ySt.insert(v[i][1]);
    ySt.insert(v[i][2]);
  }
  for (it = xSt.begin(); it != xSt.end(); it++) {
    x.push_back(*it);
  }
  for (it = ySt.begin(); it != ySt.end(); it++) {
    y.push_back(*it);
  }
  cntRws = (2 * y.size()) + 1;
  cntCls = (2 * x.size()) + 1;
  for (int i = 1; i <= cntRws; i++) {
    for (int j = 1; j <= cntCls; j++) {
      g[i][j] = 0;
      vst[i][j] = false;
    }
  }
  for (int i = 1; i <= n; i++) {
    bIdx = 2 * ((lower_bound(x.begin(), x.end(), h[i][0]) - x.begin()) + 1);
    eIdx = 2 * ((lower_bound(x.begin(), x.end(), h[i][1]) - x.begin()) + 1);
    yIdx = 2 * ((lower_bound(y.begin(), y.end(), h[i][2]) - y.begin()) + 1);
    for (int j = bIdx; j <= eIdx; j++) {
      g[yIdx][j] = -1;
    }
  }
  for (int i = 1; i <= m; i++) {
    bIdx = 2 * ((lower_bound(y.begin(), y.end(), v[i][1]) - y.begin()) + 1);
    eIdx = 2 * ((lower_bound(y.begin(), y.end(), v[i][2]) - y.begin()) + 1);
    xIdx = 2 * ((lower_bound(x.begin(), x.end(), v[i][0]) - x.begin()) + 1);
    for (int j = bIdx; j <= eIdx; j++) {
      g[j][xIdx] = -1;
    }
  }
  for (int i = 1; i <= cntRws; i++) {
    for (int j = 1; j <= cntCls; j++) {
      if (g[i][j] < 0) continue;
      g[i][j] = clcArea(i, j);
    }
  }
  res = 0;
  rchInf = false;
  runDfs(2 * ((lower_bound(y.begin(), y.end(), 0) - y.begin()) + 1),
         2 * ((lower_bound(x.begin(), x.end(), 0) - x.begin()) + 1));
  if (rchInf)
    cout << "INF\n";
  else
    cout << res << "\n";
}
int main() {
  std::ios::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}
