#include <bits/stdc++.h>
 
using namespace std;
 
#define f0r(a, b) for (long long a = 0; a < (b); a++)
#define f1r(a, b, c) for (long long a = (b); a < (c); a++)
#define f0rd(a, b) for (long long a = (b); a >= 0; a--)
#define f1rd(a, b, c) for (long long a = (b); a >= (c); a--)
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define pb push_back
#define mp make_pair
#define f first
#define s second
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vpl = vector<pll>;
 
void fio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); 
  cout.tie(0);
}
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
/* union by size */
struct dsu {
  int n;
  vector<int> sizes, marks;
  vector<vector<int> > graph;
  ll area[2000005];

  void init(int rn) {
    n = rn;
    sizes = vector<int>(n);
    fill(sizes.begin(), sizes.end(), 1);
    marks = vector<int>(n);
    for (int i = 0; i < n; i++) marks[i] = i;
    graph = vector<vector<int> >(n);
    ms(area, 0);
  }

  void mark(int m, int node) {
    if (marks[node] == m) return;

    marks[node] = m;

    for (int i: graph[node]) mark(m, i);
  }

  void merge(int a, int b) {
    if (marks[a] == marks[b]) return;
    graph[a].push_back(b);
    graph[b].push_back(a);

    if (sizes[marks[a]] > sizes[marks[b]]) swap(a, b);

    sizes[marks[b]] += sizes[marks[a]];
    area[marks[b]] += area[marks[a]];
    sizes[marks[a]] = 0;
    mark(marks[b], a);
  }

  int f(int n) { return marks[n]; }

  void adda(ll id, ll a) {
    area[marks[id]] += a;
  }

  ll geta(ll id) {
    return area[marks[id]];
  }
};
 
const long double pi = 3.14159265358979323846;
const ll bnum = 1e9 + 17;
const ll mx = 2e6;

ll area[mx];
dsu d;

void solve() {
  ll n, m; cin >> n >> m;

  pair<ll, pll> ver[n];
  pair<ll, pll> hor[m];
  f0r(i, n) {
    cin >> ver[i].s.f >> ver[i].s.s >> ver[i].f;
  }
  f0r(i, m) {
    cin >> hor[i].f >> hor[i].s.f >> hor[i].s.s;
  }

  d.init(mx);

  set<ll> coords;
  coords.insert(bnum);
  map<ll, vpl> ve;
  map<ll, vl> st, en;
  ve[bnum].pb(mp(-bnum, bnum));
  
  set<pair<pll, ll> > segs;
  segs.insert(mp(mp(-bnum, bnum), 0));
  map<ll, vpl> ho;
  f0r(i, m) {
    ho[hor[i].f].pb(hor[i].s);
  }
  f0r(i, n) {
    ve[ver[i].f].pb(ver[i].s);
    coords.insert(ver[i].f);
  }
  for (auto x: ho) {
    sort(x.s.begin(), x.s.end());
    vpl ne;
    pll targ = mp(-bnum, -bnum);
    for (auto y: x.s) {
      if (y.f <= targ.s) {
        targ.s = max(targ.s, y.s);
      } else {
        if (targ != mp(-bnum, -bnum)) {
          coords.insert(targ.f); coords.insert(targ.s);

          st[targ.f].pb(x.f);
          en[targ.s].pb(x.f);
        }
        targ = y;
      }
    }
    coords.insert(targ.f); coords.insert(targ.s);

    st[targ.f].pb(x.f);
    en[targ.s].pb(x.f);
  }

  for (auto x: ve) {
    sort(x.s.begin(), x.s.end());
    vpl ne;
    pll targ = mp(-bnum, -bnum);
    for (auto y: x.s) {
      if (y.f <= targ.s) {
        targ.s = max(targ.s, y.s);
      } else {
        if (targ != mp(-bnum, -bnum)) ne.pb(targ);
        targ = y;
      }
    }
    ne.pb(targ);
    ve[x.f] = ne;
  }

  ll last = -bnum, lid = 1;
  int orig = -1;

  for (ll x: coords) {
    ll dif = x - last;
    for (auto x: segs) {
      ll v = x.f.s - x.f.f;
      d.adda(x.s, v * dif);
    }

    if (last <= 0 && x > 0) {
      for (auto x: segs) {
        if (x.f.f <= 0 && 0 <= x.f.s) orig = x.s;
      }
    }

    for (ll y: st[x]) {
      for (auto x: segs) {
        if (x.f.f < y && y < x.f.s) {
          segs.erase(x);
          segs.insert(mp(mp(x.f.f, y), x.s));
          segs.insert(mp(mp(y, x.f.s), x.s));
          break;
        }
      }
    }

    for (pll y: ve[x]) {
      vector<pair<pll, ll>> bad, good;
      for (auto x: segs) {
        if (y.f <= x.f.f && x.f.s <= y.s) {
          bad.pb(x);
          good.pb(mp(x.f, lid++));
        }
      }
      for (auto x: bad) segs.erase(x);
      for (auto x: good) segs.insert(x);
    }

    for (ll y: en[x]) {
      pair<pll, ll> last, next;
      for (auto x: segs) {
        if (x.f.s == y) {
          last = x;
        } else if (x.f.f == y) {
          next = x;
        }
      }
      segs.erase(last);
      segs.erase(next);
      d.merge(last.s, next.s);
      pair<pll, ll> ne = mp(mp(last.f.f, next.f.s), last.s);
      segs.insert(ne);
    }

    last = x;
  }

  if (d.f(orig) == d.f(0)) {
    cout << "INF\n";
  } else {
    cout << d.geta(orig) << '\n';
  }
}
 
int main() {
  fio();
  
  int T = 1;
  // cin >> T;
  while (T--) solve();
} 

Measured memory_bytes: 82704