#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> PLL;
#define chmax(x, y) do { x = max(x, y); } while(0)
#define chmin(x, y) do { x = min(x, y); } while(0)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) \
  for (ll i = static_cast<ll>(a); i < static_cast<ll>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, ) (__VA_ARGS__)  // NOLINT
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;

// Union Find {{{
class UnionFind {
 public:
     int n;
     std::vector<int> par;
     std::vector<int> num;

     explicit UnionFind(int n) {  // [0 n)のunion find
         this->n = n;
         this->par.resize(n);
         this->num.resize(n, 1);
         for (int i = 0; i < n; i++) {
             this->par[i] = i;
         }
     }

     int root(int i) {
         if (par[i] == i)
             return i;
         else
             return par[i] = root(par[i]);
     }

     bool same(int i, int j) {
         return root(i) == root(j);
     }

     bool unite(int i, int j) {
         int t = root(i);
         int k = root(j);

         if (t == k)
           return false;

         par[t] = k;
         num[k] += num[t];
         return true;
     }

     int size(int i) {
         return num[root(i)];
     }
};
// }}}

ll cellID(ll tx, ll ty) {
  return tx * 4000 + ty;
}
UnionFind uf(4000*4000);

struct T1 {
  ll x0, x1;
  ll y;
  T1(ll x0, ll x1, ll y) : x0(x0), x1(x1), y(y) {}
};

struct T2 {
  ll y0, y1;
  ll x;
  T2(ll y0, ll y1, ll x) : y0(y0), y1(y1), x(x) {}
};

ll N, M, X, Y;
vector<T1> hline;
vector<T2> vline;
set<ll> xs, ys;

map<ll, ll> ox, tx;
map<ll, ll> oy, ty;

const ll U = 0, D = 1, L = 2, R = 3;
const ll dx[4] = {0, 0, -1, 1};
const ll dy[4] = {-1, 1, 0, 0};
bool block[4000][4000][4];

const ll INF = LLONG_MAX;

// area[tx][ty] の面積
ull area[4000][4000];
ull total_area[4000*4000];

signed main() {
  cin >> N >> M;

  xs.insert(0);
  ys.insert(0);
  rep(i, N) {
    ll x0, x1, y;
    cin >> x0 >> x1 >> y;
    hline.emplace_back(x0, x1, y);
    xs.insert(x0);
    xs.insert(x1);
    ys.insert(y);
  }
  rep(i, M) {
    ll x, y0, y1;
    cin >> x >> y0 >> y1;
    vline.emplace_back(y0, y1, x);
    xs.insert(x);
    ys.insert(y0);
    ys.insert(y1);
  }

  // 座標圧縮
  {
    ll i = 0;
    for (auto t : xs) {
      ox[i] = t;
      tx[t] = i;
      // printf("tx[%lld]=%lld\n", t, i);
      i++;
    }
    X = i;

    i = 0;
    for (auto t : ys) {
      oy[i] = t;
      ty[t] = i;
      // printf("ty[%lld]=%lld\n", t, i);
      i++;
    }
    Y = i;
  }
  // cout << "X = " << X << endl;
  // cout << "y = " << Y << endl;

  // block[x][y][dir] を算出
  rep(i, N) {
    auto [x0, x1, y0] = hline[i];
    ll tx0 = tx[x0], tx1 = tx[x1], ty0 = ty[y0];
    // printf("hline (%lld,%lld) -> (%lld,%lld)\n", tx0, ty0, tx1, ty0);
    for (ll tx = tx0; tx < tx1;  tx++) {
      if (ty0-1 >= 0) block[tx][ty0-1][D] = true;
      if (ty0 < Y-1)  block[tx][ty0][U]   = true;
    }
  }
  rep(i, M) {
    auto [y0, y1, x0] = vline[i];
    ll ty0 = ty[y0], ty1 = ty[y1], tx0 = tx[x0];
    // printf("vline (%lld,%lld) -> (%lld,%lld)\n", tx0, ty0, tx0, ty1);
    for (ll ty = ty0; ty < ty1;  ty++) {
      if (tx0-1 >= 0) block[tx0-1][ty][R] = true;
      if (tx0 < X-1)  block[tx0][ty][L]   = true;
    }
  }

  // UnionFind で結合
  // 各セルの面積を算出
  rep(tx, X-1) {
    rep(ty, Y-1) {
      ll l = ox[tx], r = ox[tx+1];
      ll u = oy[ty], d = oy[ty+1];
      area[tx][ty] = (r-l)*(d-u);
      ll cid1 = cellID(tx, ty);

      // printf("area: cid = %lld tx = %lld ty = %lld\n", cid1, tx, ty);
      // printf("cid = %lld area[%lld][%lld] = (%lld-%lld) x (%lld-%lld) = %lld\n", cid1, tx, ty, r, l, d, u, area[tx][ty]);

      rep(k, 4) {
        if (block[tx][ty][k])
          continue;
        ll tx2 = tx + dx[k];
        ll ty2 = ty + dy[k];
        if (tx2 < 0 || ty2 < 0 || tx2 > X-2 || ty2 > Y-2) {
          // 外部と結合
          area[tx][ty] = INF;
        } else {
          // 隣のセルと結合
          ll cid2 = cellID(tx2, ty2);
          uf.unite(cid1, cid2);
        }
      }
    }
  }

  // 各セルの面積を集計
  rep(tx, X-1) {
    rep(ty, Y-1) {
      ll cid = cellID(tx, ty);
      if (total_area[uf.root(cid)] == INF || area[tx][ty] == INF) {
        total_area[uf.root(cid)] = INF;
        // printf("total_area[%d] = INF\n", uf.root(cid));
      } else {
        total_area[uf.root(cid)] += area[tx][ty];
        // printf("total_area[%d] += %lld\n", uf.root(cid), area[tx][ty]);
      }
    }
  }

  ll cid = cellID(tx[0], ty[0]);
  // printf("ans: cid = %lld tx = %lld ty = %lld\n", cid, tx[0], ty[0]);
  ll ans = total_area[uf.root(cid)];
  if (ans == INF || ans == 0) {
    cout << "INF" << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 275688