#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

template<class T> inline bool chmin(T& a,T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if (a < b) {a = b; return true;} return false;}

const ll MOD = 1000000007;
const ll INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

struct L{
  ll a, b, c;
  L(ll a = 0, ll b = 0, ll c = 0): a(a), b(b), c(c){}
};

const ll dx[] = {-1, 0, 1, 0};
const ll dy[] = {0, -1, 0, 1};

ll main(){
  ll N, M; cin >> N >> M;
  //元々の座標
  //first: 元々の座標　second:圧縮後の座標
  map<ll, ll> mpX, mpY;
  mpX[0] = 0, mpY[0] = 0;

  vector<L> lh, lv;
  rep(i, N){
    ll a, b, c; cin >> a >> b >> c;
    mpX[a] = 0;
    mpX[b] = 0;
    mpY[c] = 0;
    lh.emplace_back(a, b, c);
  }
  rep(i, M){
    ll a, b, c; cin >> c >> a >> b;
    mpY[a] = 0;
    mpY[b] = 0;
    mpX[c] = 0;
    lv.emplace_back(a, b, c);
  }
  //圧縮する前の座標
  //xs[0]:圧縮後の座標0の元座標
  vector<ll> xs, ys;
  for(auto& p: mpX){
    p.second = xs.size();
    xs.push_back(p.first);
  }
  for(auto& p: mpY){
    p.second = ys.size();
    ys.push_back(p.first);
  }

  //扱うグリッドのサイズ
  ll h = xs.size() * 2;
  ll w = ys.size() * 2;
  vector<vector<ll>> d(h, vector<ll>(w));
  rep(i, N){
    ll a = mpX[lh[i].a] * 2;
    ll b = mpX[lh[i].b] * 2;
    ll c = mpY[lh[i].c] * 2;
    for (ll x = a; x <= b; ++x) d[x][c] = -1;
  }
  rep(i, N){
    ll a = mpY[lv[i].a] * 2;
    ll b = mpY[lv[i].b] * 2;
    ll c = mpX[lv[i].c] * 2;
    for (ll y = a; y <= b; ++y) d[c][y] = -1;
  }

  queue<P> q;
  ll sx = mpX[0] * 2, sy = mpY[0] * 2;
  d[sx][sy] = 1;//たどり着けるところを1にする
  q.push(P(sx, sy));
  while (!q.empty()){
    ll x = q.front().first;
    ll y = q.front().second;
    q.pop();
    rep(v, 4){
      ll nx = x + dx[v], ny = y + dy[v];
      if (nx < 0 || nx >= h) continue;
      if (ny < 0 || ny >= w) continue;
      if (d[nx][ny] != 0) continue;
      d[nx][ny] = 1;
      q.push(P(nx, ny));
    }
  }

  ll ans = 0;
  rep(x, h) rep(y, w){
    if (d[x][y] != 1) continue;
    if (x == 0 || x == h - 1 || y == 0 || y == w - 1){
      cout << "INF" << endl;
      return 0;
    }
    if (x % 2 == 0 || y % 2 == 0) continue;
    ll ex = xs[x / 2 + 1] - xs[x / 2];
    ll ey = ys[y / 2 + 1] - ys[y / 2];
    ans += ex * ey;
  }
  cout << ans << endl;
}
