#include <bits/stdc++.h>
#include <variant>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,m;
  cin>>n>>m;
  set<ll> xs, ys;
  vector<tuple<ll,ll,ll>> vl, hl;
  REP(i,n) {
    ll a,b,c;
    cin>>a>>b>>c;
    xs.insert(a);
    xs.insert(b);
    ys.insert(c);
    vl.emplace_back(a,b,c);
  }
  REP(i,m) {
    ll a,b,c;
    cin>>a>>b>>c;
    xs.insert(a);
    ys.insert(b);
    ys.insert(c);
    hl.emplace_back(a,b,c);
  }
  vecll vxs(ALL(xs));
  vecll vys(ALL(ys));
  int xc = size(vxs)+1;
  int yc = size(vys)+1;
  map<ll, ll> to_xid, to_yid;
  REP(i,xc-1) to_xid[vxs[i]] = i+1;
  REP(i,yc-1) to_yid[vys[i]] = i+1;
  int v = xc * yc;
  vector<int> g(v);
  array<int, 4> di = {1, 0, -1, 0};
  array<int, 4> dj = {0, -1, 0, 1};
  auto id = [&] (int i, int j) {
    return i * xc + j;
  };
  REP(i,yc) {
    REP(j,xc) {
      REP(k,4) {
        int ni = i + di[k];
        int nj = j + dj[k];
        if (ni < 0 || ni >= yc || nj < 0 || nj >= xc) continue;
        g[id(i,j)] |= 1 << k;
      }
    }
  }
  for(auto&&[a,b,c]:vl) {
    ll s = to_xid[a];
    ll t = to_xid[b];
    ll y = to_yid[c];
    FOR(x,s,t) {
      g[id(y-1,x)] &= ~(1 << 0);
      g[id(y,x)] &= ~(1 << 2);
    }
  }
  for(auto&&[a,b,c]:hl) {
    ll x = to_xid[a];
    ll s = to_yid[b];
    ll t = to_yid[c];
    FOR(y,s,t) {
      g[id(y,x-1)] &= ~(1 << 3);
      g[id(y,x)] &= ~(1 << 1);
    }
  }
  auto xzero = upper_bound(ALL(vxs), 0) - begin(vxs);
  auto yzero = upper_bound(ALL(vys), 0) - begin(vys);
  vector<bool> vis(v, false);
  queue<int> q;
  q.push(id(yzero,xzero));
  vis[id(yzero,xzero)] = true;
  while (!q.empty()) {
    int idx = q.front();
    q.pop();
    int to = g[idx];
    int i = idx / xc;
    int j = idx % xc;
    REP(k,4) {
      if ((to>>k)&1) {
        int ni = i + di[k];
        int nj = j + dj[k];
        if (!vis[id(ni,nj)]) {
          vis[id(ni,nj)] = true;
          q.push(id(ni,nj));
        }
      }
    }
  }
  ll sum = 0;
  REP(i,yc){
    REP(j,xc) {
      if (vis[id(i,j)]) {
        if (i == 0 || i == yc-1 || j == 0 || j == xc-1) {
          cout<<"INF\n";
          return 0;
        }
        sum += (vys[i] - vys[i-1]) * (vxs[i] - vxs[i-1]);
      }
    }
  }
  cout<<sum<<endl;
  return 0;
}
