#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

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

int main(){
	cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);

	ll n, m;cin >> n >> m;
	vector<pair<P, ll> > tate;
	vector<pair<P, ll> > yoko;
	vector<ll> Xs({0});
	vector<ll> Ys({0});
	REP(i, n){
		ll a, b, c;cin >> a >> b >> c;
		Ys.PB(a);
		Ys.PB(b);
		Xs.PB(c);
		tate.EB(MP(a, b), c);
	}
	REP(i, m){
		ll a, b, c;cin >> a >> b >> c;
		Xs.PB(b);
		Xs.PB(c);
		Ys.PB(a);
		yoko.EB(MP(b, c), a);
	}

	sort(ALL(Xs));
	sort(ALL(Ys));
	Xs.erase(unique(ALL(Xs)), Xs.end());
	Ys.erase(unique(ALL(Ys)), Ys.end());

	vector<vector<char> > mp(2 * Ys.size() + 1,
												vector<char>(2 * Xs.size() + 1, '.'));

	REP(i, n){
		ll y_from = 2 * (lower_bound(ALL(Ys), tate[i].FI.FI) - Ys.begin()) + 1;
		ll y_to = 2 * (lower_bound(ALL(Ys), tate[i].FI.SE) - Ys.begin()) + 1;
		ll x = 2 * (lower_bound(ALL(Xs), tate[i].SE) - Xs.begin()) + 1;
		for(ll y = y_from;y <= y_to;y++)mp[y][x] ='#';
	}

	REP(i, m){
		ll x_from = 2 * (lower_bound(ALL(Xs), yoko[i].FI.FI) - Xs.begin()) + 1;
		ll x_to = 2 * (lower_bound(ALL(Xs), yoko[i].FI.SE) - Xs.begin()) + 1;
		ll y = 2 * (lower_bound(ALL(Ys), yoko[i].SE) - Ys.begin()) + 1;
		for(ll x = x_from;x <= x_to;x++)mp[y][x] = '#';
	}

	ll h = mp.size();
	ll w = mp[0].size();
	//SHOW2d(mp, h, w);

	queue<P> q;
	ll ys = 2 * (lower_bound(ALL(Ys), 0) - Ys.begin()) + 1;
	ll xs = 2 * (lower_bound(ALL(Xs), 0) - Xs.begin()) + 1;
	q.push(MP(ys, xs));
	mp[ys][xs] = 'o';
	while(!q.empty()){
		ll y = q.front().FI;
		ll x = q.front().SE;
		q.pop();

		REP(i, 4){
			ll yy = y + dy[i];
			ll xx = x + dx[i];
			if(yy < 0 || xx < 0 || yy >= h || xx >= w)continue;
			if(mp[yy][xx] != '.')continue;
			mp[yy][xx] = 'o';
			q.push(MP(yy, xx));
		}
	}

	//SHOW2d(mp, h, w);

	if(mp[0][0] == 'o'){
		cout << "INF" << endl;
		return 0;
	}

	ll ans = 0;
	REP(i, Ys.size() - 1)REP(j, Xs.size() - 1){
		ll y = 2 * (i + 1);
		ll x = 2 * (j + 1);
		if(mp[y][x] != 'o')continue;
		ll H = Ys[i + 1] - Ys[i];
		ll W = Xs[j + 1] - Xs[j];
		ans += H * W;
	}

	cout << ans << endl;

	return 0;
}
