#include <bits/stdc++.h>
using Graph = std::vector<std::vector<long long> >;
const long long INF = 1e17;
struct UnionFind {
  long long n;
  std::vector<long long> par, size;
  UnionFind(long long sz) : n(sz), par(sz, 0), size(sz, 1) {
    std::iota(par.begin(), par.end(), 0);
  }
  long long find(long long x) {
    if (par[x] == x) return x;
    return par[x] = find(par[x]);
  }
  void unite(long long x, long long y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (size[x] < size[y]) std::swap(x, y);
    size[x] += size[y];
    par[y] = x;
  }
};
struct L {
  long long a, b, c;
  L(long long a, long long b, long long c) : a(a), b(b), c(c) {}
};
signed main() {
  long long n, m;
  std::cin >> n >> m;
  std::set<long long> setx, sety;
  std::vector<L> X, Y;
  for (long long i = 0; i < (n); i++) {
    long long a, b, c;
    std::cin >> a >> b >> c;
    X.emplace_back(a, b, c);
    setx.emplace(a);
    setx.emplace(b);
    sety.emplace(c);
  }
  for (long long i = 0; i < (m); i++) {
    long long a, b, c;
    std::cin >> a >> b >> c;
    Y.emplace_back(b, c, a);
    sety.emplace(b);
    sety.emplace(c);
    setx.emplace(a);
  }
  std::vector<long long> zx, zy;
  for (auto x : setx) zx.emplace_back(x);
  for (auto y : sety) zy.emplace_back(y);
  long long h = zx.size();
  long long w = zy.size();
  UnionFind uf((h + 1) * (w + 1));
  std::vector<std::vector<long long> > XX(w + 1,
                                          std::vector<long long>(h + 1, 0));
  std::vector<std::vector<long long> > YY(h + 1,
                                          std::vector<long long>(w + 1, 0));
  auto findx = [&](long long x) -> long long {
    return std::lower_bound((zx).begin(), (zx).end(), x) - zx.begin();
  };
  auto findy = [&](long long y) -> long long {
    return std::lower_bound((zy).begin(), (zy).end(), y) - zy.begin();
  };
  for (auto p : X) {
    long long a = findx(p.a);
    long long b = findx(p.b);
    long long c = findy(p.c);
    XX[c][a]++;
    XX[c][b + 1]--;
  }
  for (auto p : Y) {
    long long a = findy(p.a);
    long long b = findy(p.b);
    long long c = findx(p.c);
    YY[c][a]++;
    YY[c][b + 1]--;
  }
  auto enc = [&](long long i, long long j) -> long long {
    return i * (w + 1) + j;
  };
  {
    for (long long i = 0; i < (w); i++) {
      long long ac = 0;
      for (long long j = 0; j < (h); j++) {
        ac += XX[i][j];
        XX[i][j] = ac;
      }
    }
  }
  {
    for (long long i = 0; i < (h); i++) {
      long long ac = 0;
      for (long long j = 0; j < (w); j++) {
        ac += YY[i][j];
        YY[i][j] = ac;
      }
    }
  };
  for (long long i = 0; i < (h + 1); i++) {
    for (long long j = 0; j < (w + 1); j++) {
      if (i <= 0 || j >= w || XX[j][i - 1] == 0) {
        uf.unite(enc(i, j), enc(i, j + 1));
      }
      if (j <= 0 || i >= h || YY[i][j - 1] == 0) {
        uf.unite(enc(i, j), enc(i + 1, j));
      }
    }
  }
  long long sx = findx(0);
  long long sy = findy(0);
  long long cl = uf.find(enc(sx, sy));
  long long ans = 0;
  for (long long i = 0; i < (h + 1); i++) {
    for (long long j = 0; j < (w + 1); j++) {
      if (uf.find(enc(i, j)) != cl) continue;
      if (i == 0 || j == 0 || i == h || j == w) {
        std::cout << ("INF") << '\n';
        return 0;
      }
      ans += (zx[i] - zx[i - 1]) * (zy[j] - zy[j - 1]);
    }
  }
  std::cout << (ans) << '\n';
  return 0;
}
