#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20);
  ll N, M;
  cin >> N >> M;
  vll A(N), B(N), C(N);
  vll D(M), E(M), F(M);
  for (ll i = 0; i < (ll)N; ++i) cin >> A[i] >> B[i] >> C[i];
  for (ll i = 0; i < (ll)M; ++i) cin >> D[i] >> E[i] >> F[i];
  set<ll> xs = {0}, ys = {0};
  for (ll i = 0; i < (ll)N; ++i) {
    xs.insert(A[i]);
    xs.insert(B[i]);
    ys.insert(C[i]);
  }
  for (ll i = 0; i < (ll)M; ++i) {
    ys.insert(E[i]);
    ys.insert(F[i]);
    xs.insert(D[i]);
  }
  unordered_map<ll, ll> xm, ym;
  vll xv(xs.size()), yv(ys.size());
  ll idx = 0;
  for (ll x : xs) {
    xm[x] = idx;
    xv[idx++] = x;
  }
  idx = 0;
  for (ll y : ys) {
    ym[y] = idx;
    yv[idx++] = y;
  }
  vvll m(ys.size() * 2, vll(xs.size() * 2, 0));
  for (ll i = 0; i < (ll)N; ++i)
    for (ll j = xm[A[i]] * 2; j < (ll)xm[B[i]] * 2 + 1; ++j)
      m[ym[C[i]] * 2][j] = 1;
  for (ll i = 0; i < (ll)M; ++i)
    for (ll j = ym[E[i]] * 2; j < (ll)ym[F[i]] * 2 + 1; ++j)
      m[j][xm[D[i]] * 2] = 1;
  ll cx = xm[0] * 2, cy = ym[0] * 2, a = 0;
  vvll dirs = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
  vvll s(ys.size() * 2, vll(xs.size() * 2, 0));
  queue<pair<ll, ll>> q;
  q.push({cx, cy});
  s[cy][cx] = 1;
  while (!q.empty()) {
    auto p = q.front();
    q.pop();
    if (p.first == 0 || p.first == xs.size() * 2 - 2 || p.second == 0 ||
        p.second == ys.size() * 2 - 2) {
      cout << "INF" << endl;
      return 0;
    }
    if (p.first % 2 == 1 && p.second % 2 == 1)
      a += (xv[p.first / 2 + 1] - xv[p.first / 2]) *
           (yv[p.second / 2 + 1] - yv[p.second / 2]);
    for (auto d : dirs) {
      ll nx = p.first + d[0], ny = p.second + d[1];
      if (!s[ny][nx] && !m[ny][nx]) q.push({nx, ny}), s[ny][nx] = 1;
    }
  }
  cout << a << endl;
}
