#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  static tuple<int64_t, int64_t, int64_t> abc[1000], def[1000];
  static int64_t xv[1000], yv[1000];
  cin >> n >> m;
  map<int64_t, int> xs, ys;
  for (int i = 0; i < n; ++i) {
    int64_t a, b, c;
    cin >> a >> b >> c;
    if (a > b) swap(a, b);
    abc[i] = {a, b, c};
    xs[a] = 0;
    xs[b] = 0;
    ys[c] = 0;
  }
  for (int j = 0; j < m; ++j) {
    int d, e, f;
    cin >> d >> e >> f;
    if (e > f) swap(e, f);
    def[j] = {d, e, f};
    xs[d] = 0;
    ys[e] = 0;
    ys[f] = 0;
  }
  int cx = 0, cy = 0;
  for (auto &x : xs) {
    xv[cx] = x.first;
    x.second = cx++;
  }
  for (auto &y : ys) {
    yv[cy] = y.first;
    y.second = cy++;
  }
  static bool tate[3000][3000], yoko[3000][3000];
  for (int i = 0; i < n; ++i) {
    auto [a, b, c] = abc[i];
    for (int xi = xs[a] + 1; xi <= xs[b]; ++xi) {
      tate[xi][ys[c]] = true;
    }
  }
  for (int i = 0; i < m; ++i) {
    auto [d, e, f] = def[i];
    for (int yi = ys[e] + 1; yi <= ys[f]; ++yi) {
      yoko[xs[d]][yi] = true;
    }
  }
  int zxi, zyi;
  zxi = lower_bound(xv, xv + cx, 0) - xv;
  zyi = lower_bound(yv, yv + cy, 0) - yv;
  uint64_t ans = 0;
  static bool checked[3000][3000];
  queue<pair<int, int>> q;
  q.emplace(zxi, zyi);
  checked[zxi][zyi] = true;
  if (zxi <= 0 || zxi >= cx || zyi <= 0 || zyi >= cy) goto l_inf;
  while (!q.empty()) {
    auto [xi, yi] = q.front();
    ans += (xv[xi] - xv[xi - 1]) * (yv[yi] - yv[yi - 1]);
    q.pop();
    if (!yoko[xi - 1][yi]) {
      if (xi - 1 <= 0) goto l_inf;
      if (!checked[xi - 1][yi]) {
        checked[xi - 1][yi] = true;
        q.emplace(xi - 1, yi);
      }
    }
    if (!yoko[xi][yi]) {
      if (xi + 1 >= cx) goto l_inf;
      if (!checked[xi + 1][yi]) {
        checked[xi + 1][yi] = true;
        q.emplace(xi + 1, yi);
      }
    }
    if (!tate[xi][yi - 1]) {
      if (yi - 1 <= 0) goto l_inf;
      if (!checked[xi][yi - 1]) {
        checked[xi][yi - 1] = true;
        q.emplace(xi, yi - 1);
      }
    }
    if (!tate[xi][yi]) {
      if (yi + 1 >= cy) goto l_inf;
      if (!checked[xi][yi + 1]) {
        checked[xi][yi + 1] = true;
        q.emplace(xi, yi + 1);
      }
    }
  }
  cout << ans << endl;
  return 0;
l_inf:
  cout << "INF" << endl;
  return 0;
}
