#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using VVVbo = vector<VVbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(ll i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(ll i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;

// compress vector
template<typename T>
pair<map<T, int>, vector<T>> compress(vector<T> v) {
  sort(all(v));
  v.erase(unique(all(v), v.end());
  map<T, int> zip;
  rep(i, v.size()) zip[v[i]] = i;
  return {move(zip), move(v)};
}

V dx = {1, 0, -1, 0};
V dy = {0, 1, 0, -1};

int main() {
  ll n, m; cin >> n >> m;
  
  V x, y;
  x.push_back(-INF);
  y.push_back(-INF);
  x.push_back(INF);
  y.push_back(INF);
  x.push_back(0);
  y.push_back(0);


  vector<tuple<int,int,int>> lx, ly;

  rep(i, n) {
    int a, b, c; cin >> a >> b >> c;
    x.push_back(a);
    x.push_back(b);
    y.push_back(c);
    lx.emplace_back(a, b, c);
  }
  rep(i, m) {
    int a, b, c; cin >> a >> b >> c;
    x.push_back(a);
    y.push_back(b);
    y.push_back(c);
    ly.emplace_back(a, b, c);
  }
  auto [xz, xu] = compress(x);
  auto [yz, yu] = compress(y);

  int X = x.size()-1;
  int Y = y.size()-1;
  VVVbo blk(X, VVbo(Y, Vbo(4)));
  for (auto &[a, b, c] : lx) {
    rep2(i, xz[a], xz[b]) {
      blk[i][yz[c]-1][1] = true;
      blk[i][yz[c]][3] = true;
    }
  }
  for (auto &[c, a, b] : ly) {
    rep2(i, yz[a], yz[b]) {
      blk[xz[c]-1][i][0] = true;
      blk[xz[c]][i][2] = true;
    }
  }

  ll ans = 0;

  VVbo seen(X, Vbo(Y));
  queue<P> que;
  que.emplace(xz[0], yz[0]);
  seen[xz[0]][yz[0]] = true;
  while (!que.empty()) {
    auto [i, j] = que.front(); que.pop();
    ans += ll(xu[i+1] - xu[i]) * ll(yu[j+1] - yu[j]);
    rep(dir, dx.size()) {
      if (blk[i][j][dir]) continue;
      int ii = i + dx[dir];
      int jj = j + dy[dir];
      if (ii < 0 || ii >= X || jj < 0 || jj >= Y) continue;
      if (!seen[ii][jj]) {
        que.emplace(ii, jj);
        seen[ii][jj] = true;
      }
    }
  }
  if (seen[0][0]) cout << "INF\n";
  else cout << ans << "\n";
  return 0;
}
