#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<long long> xval, yval;
  vector<tuple<int, int, int>> ve, ho;
  for (int i = 0; i < n; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    xval.emplace_back(a);
    xval.emplace_back(b);
    yval.emplace_back(c);
    ho.emplace_back(a, b, c);
  }
  for (int i = 0; i < m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    yval.emplace_back(b);
    yval.emplace_back(c);
    xval.emplace_back(a);
    ve.emplace_back(b, c, a);
  }
  sort(begin(xval), end(xval));
  xval.erase(unique(begin(xval), end(xval)), end(xval));
  sort(begin(yval), end(yval));
  yval.erase(unique(begin(yval), end(yval)), end(yval));
  int ro[3030][3030] = {}, co[3030][3030] = {};
  for (auto [a, b, c] : ho) {
    a = lower_bound(begin(xval), end(xval), a) - begin(xval);
    b = lower_bound(begin(xval), end(xval), b) - begin(xval);
    c = lower_bound(begin(yval), end(yval), c) - begin(yval);
    co[c][a + 1]++;
    co[c][b + 1]--;
  }
  for (auto [a, b, c] : ve) {
    a = lower_bound(begin(yval), end(yval), a) - begin(yval);
    b = lower_bound(begin(yval), end(yval), b) - begin(yval);
    c = lower_bound(begin(xval), end(xval), c) - begin(xval);
    ro[c][a + 1]++;
    ro[c][b + 1]--;
  }
  for (int i = 0; i <= 2000; ++i) {
    for (int j = 0; j <= 2000; ++j) {
      ro[i][j + 1] += ro[i][j];
      co[i][j + 1] += co[i][j];
    }
  }
  auto cango = [&](int nowx, int nowy, int tox, int toy) -> bool {
    if (tox < 0 or toy < 0 or tox > xval.size() or toy > yval.size())
      return false;
    if (nowx == tox) {
      if (nowy > toy) swap(nowy, toy);
      return !co[nowy][nowx];
    } else {
      if (nowx > tox) swap(nowx, tox);
      return !ro[nowx][nowy];
    }
  };
  queue<pair<int, int>> qu;
  int sx = upper_bound(begin(xval), end(xval), 0) - begin(xval);
  int sy = upper_bound(begin(yval), end(yval), 0) - begin(yval);
  qu.emplace(sx, sy);
  bool flag[3030][3030] = {};
  flag[sx][sy] = 1;
  while (!qu.empty()) {
    auto [fx, fy] = qu.front();
    qu.pop();
    if (cango(fx, fy, fx - 1, fy))
      if (!flag[fx - 1][fy]) flag[fx - 1][fy] = 1, qu.emplace(fx - 1, fy);
    if (cango(fx, fy, fx + 1, fy))
      if (!flag[fx + 1][fy]) flag[fx + 1][fy] = 1, qu.emplace(fx + 1, fy);
    if (cango(fx, fy, fx, fy - 1))
      if (!flag[fx][fy - 1]) flag[fx][fy - 1] = 1, qu.emplace(fx, fy - 1);
    if (cango(fx, fy, fx, fy + 1))
      if (!flag[fx][fy + 1]) flag[fx][fy + 1] = 1, qu.emplace(fx, fy + 1);
  }
  long long ans = 0;
  for (size_t i = 0; i <= xval.size(); ++i) {
    bool iinf = !i or i == xval.size();
    for (size_t j = 0; j <= yval.size(); ++j) {
      bool jinf = !j or j == yval.size();
      if (flag[i][j]) {
        if (iinf or jinf) {
          cout << "INF"
               << "\n";
          return 0;
        }
        ans += (xval[i] - xval[i - 1]) * (yval[j] - yval[j - 1]);
      }
    }
  }
  cout << ans << endl;
}
