#include <bits/stdc++.h>
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = acos(-1);
using namespace std;
struct INIT {
  INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  }
} INIT;
struct L {
  ll a, b, c;
  L(ll a = 0, ll b = 0, ll c = 0) : a(a), b(b), c(c) {}
};
ll dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
ll dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
signed main() {
  ll N, M;
  cin >> N >> M;
  vector<L> xx, yy;
  map<ll, ll> mx, my;
  mx[0] = 0;
  my[0] = 0;
  for (ll i = 0; i < ll(N); ++i) {
    ll a, b, c;
    cin >> a >> b >> c;
    mx[a] = 0;
    mx[b] = 0;
    my[c] = 0;
    xx.emplace_back(a, b, c);
  }
  for (ll i = 0; i < ll(M); ++i) {
    ll a, b, c;
    cin >> a >> b >> c;
    mx[a] = 0;
    my[b] = 0;
    my[c] = 0;
    yy.emplace_back(a, b, c);
  }
  vector<ll> xs, ys;
  for (auto& p : mx) {
    p.second = xs.size();
    xs.emplace_back(p.first);
  }
  for (auto& p : my) {
    p.second = ys.size();
    ys.emplace_back(p.first);
  }
  ll sx = mx[0] * 2;
  ll sy = my[0] * 2;
  ll H = xs.size() * 2;
  ll W = ys.size() * 2;
  vector<vector<ll>> d(H, vector<ll>(W));
  d[sx][sy] = 1;
  for (ll i = 0; i < ll(N); ++i) {
    ll a = mx[xx[i].a] * 2;
    ll b = mx[xx[i].b] * 2;
    ll c = my[xx[i].c] * 2;
    for (ll j = (a); j < (b + 1); ++j) d[j][c] = -1;
  }
  for (ll i = 0; i < ll(M); ++i) {
    ll a = mx[yy[i].a] * 2;
    ll b = my[yy[i].b] * 2;
    ll c = my[yy[i].c] * 2;
    for (ll j = (b); j < (c + 1); ++j) d[a][j] = -1;
  }
  queue<pair<ll, ll>> q;
  q.emplace(sx, sy);
  while (!q.empty()) {
    auto [x, y] = q.front();
    q.pop();
    for (ll i = 0; i < ll(4); ++i) {
      ll nx = x + dx[i];
      ll ny = y + dy[i];
      if ((nx < 0 || H <= nx) || (ny < 0 || W <= ny)) continue;
      if (d[nx][ny] != 0) continue;
      d[nx][ny] = 1;
      q.emplace(nx, ny);
    }
  }
  ll ans = 0;
  for (ll i = 0; i < ll(H); ++i)
    for (ll j = 0; j < ll(W); ++j) {
      if (d[i][j] != 1) continue;
      if (i % 2 == 0 || j % 2 == 0) continue;
      if (i == 0 || i == H - 1 || j == 0 || j == W - 1) {
        cout << "INF"
             << "\n";
        return 0;
      }
      ll ex = xs[i / 2 + 1] - xs[i / 2];
      ll ey = ys[i / 2 + 1] - ys[i / 2];
      ans += ex * ey;
    }
  cout << ans << "\n";
  return 0;
}
