#include <bits/stdc++.h>
using namespace std;
const int N = 6100, oo = -2;
long long n, m, h[N][4], v[N][4], cntRws, cntCls, bIdx, eIdx, yIdx, xIdx, res;
bool rchInf;
bitset<N> g[N], vst[N];
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;
  try {
    if (i % 2 == 0 || j % 2 == 0) return 0;
    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];
  } catch (exception e) {
  }
  return dx * dy;
}
bool vld(int i, int j) {
  bool ret;
  try {
    ret = (i >= 1 && i <= cntRws && j >= 1 && j <= cntCls && !vst[i][j] &&
           g[i][j]);
  } catch (exception e) {
  }
  return ret;
}
void runDfs(int i, int j) {
  try {
    if (vld(i, j)) {
      vst[i][j] = true;
      long long crrArea = clcArea(i, j);
      if (crrArea == oo) rchInf = true;
      res += crrArea;
      runDfs(i, j - 1);
      runDfs(i, j + 1);
      runDfs(i - 1, j);
      runDfs(i + 1, j);
    }
  } catch (exception e) {
  }
}
void solve() {
  try {
    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] = true;
        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] = false;
      }
    }
    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] = false;
      }
    }
    res = 0;
    rchInf = false;
    int orgnRwIdx = 2 * ((lower_bound(y.begin(), y.end(), 0) - y.begin()) + 1);
    int orgnClIdx = 2 * ((lower_bound(x.begin(), x.end(), 0) - x.begin()) + 1);
    runDfs(orgnRwIdx, orgnClIdx);
    if (rchInf)
      cout << "INF\n";
    else
      cout << res << "\n";
  } catch (exception e) {
  }
}
int main() {
  std::ios::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}
