#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>;
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(a.begin(), a.end(), r) -
         lower_bound(a.begin(), a.end(), l);
}
inline int Log2(ll x) {
  int k;
  for (k = 0; x > 0; ++k) x >>= 1;
  return k;
}
const int INF = 1 << 30;
const ll INFll = 1ll << 62;
const ld EPS = 1e-10;
const int MOD = int(1e9) + 7;
template <typename T>
pair<map<T, int>, vector<T>> compress(vector<T> &v) {
  vector<T> unzip = v;
  sort(unzip.begin(), unzip.end());
  unzip.erase(unique(unzip.begin(), unzip.end()), unzip.end());
  map<T, int> zip;
  for (ll i = int(0); i < int(unzip.size()); ++i) zip[unzip[i]] = i;
  return {move(zip), move(unzip)};
}
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(0);
  y.push_back(0);
  vector<tuple<int, int, int>> lx, ly;
  for (ll i = int(0); i < int(n); ++i) {
    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);
  }
  for (ll i = int(0); i < int(m); ++i) {
    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) {
    for (ll i = int(xz[a]); i < int(xz[b]); ++i) {
      blk[i][yz[c] - 1][1] = true;
      blk[i][yz[c]][3] = true;
    }
  }
  for (auto &[c, a, b] : ly) {
    for (ll i = int(yz[a]); i < int(yz[b]); ++i) {
      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]);
    for (ll dir = int(0); dir < int(dx.size()); ++dir) {
      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;
}
