#include<bits/stdc++.h>
using namespace std;

using lnt = long long;
using Real = long double;

#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(lnt i=0;i<(n);++i)
#define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
#define RREP(i, n) for(lnt i=(n)-1;i>= 0;--i)

#define ln '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define dcout cout<<fixed<<setprecision(20)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)

constexpr int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
constexpr Real eps = 1e-9; const Real pi = acosl(-1);
constexpr lnt BIG = INT_MAX/10, BBIG = LLONG_MAX/10;

template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<class T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<class T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

using pint = pair<int, int>; using plnt = pair<lnt, lnt>;
using vint = vector<int>; using vlnt = vector<lnt>;
constexpr lnt MOD = 1e9+7;

int main(){
	summon_tourist;

	lnt N, M; cin >> N >> M;
	lnt A[1000], B[1000], C[1000], D[1000], E[1000], F[1000];
	map<lnt, lnt> tate, yoko;
	const lnt CST = 1e9+10000;

	tate[0] = yoko[0] = tate[-CST] = yoko[-CST] = tate[CST] = yoko[CST] = -1;
	REP(i, N){
		cin >> A[i] >> B[i] >> C[i];
		tate[A[i]] = -1;
		tate[B[i]] = -1;
		yoko[C[i]] = -1;
	}
	REP(i, M){
		cin >> D[i] >> E[i] >> F[i];
		tate[D[i]] = -1;
		yoko[E[i]] = -1;
		yoko[F[i]] = -1;
	}

	lnt tmp = 0;
	lnt invtate[3010], invyoko[3010];

	for(auto &e : tate){
		e.second = tmp;
		invtate[tmp] = e.first;
		tmp++;
	}
	tmp = 0;
	for(auto &e : yoko){
		e.second = tmp;
		invyoko[tmp] = e.first;
		tmp++;
	}

	lnt tatesiz = tate.size(), yokosiz = yoko.size();

	lnt initx, inity;
	using area = pair<plnt, plnt>;

	vector<vector<area>> field(tatesiz-1, vector<area>(yokosiz-1, {{0, 0}, {0, 0}}));

	REP(i, tatesiz-1) {
		REP(j, yokosiz-1){
			field[i][j] = {{invtate[i], invtate[i+1]}, {invyoko[j], invyoko[j+1]}};
			if(invtate[i] == 0 and invyoko[j] == 0){
				initx = i; inity = j;
			}
		}
	}

	vector<vlnt> tateimos(yokosiz, vlnt(tatesiz-1, 0));
	REP(i, N){
		lnt up = tate[A[i]], down = tate[B[i]];
		lnt yy = yoko[C[i]];

		tateimos[yy][up]++;
		tateimos[yy][down]--;
	}
	REP(i, yokosiz) RANGE(j, 1, tatesiz-1){
		tateimos[i][j] += tateimos[i][j-1];
	}

	vector<vlnt> yokoimos(tatesiz, vlnt(yokosiz-1, 0));
	REP(i, M){
		lnt left = yoko[E[i]], right = yoko[F[i]];
		lnt xx = tate[D[i]];

		yokoimos[xx][left]++;
		yokoimos[xx][right]--;
	}
	REP(i, tatesiz) RANGE(j, 1, yokosiz-1){
		yokoimos[i][j] += yokoimos[i][j-1];
	}

	queue<plnt> que; que.push({initx, inity});
	vector<vector<bool>> visit(tatesiz-1, vector<bool>(yokosiz-1, 0));
	visit[initx][inity] = 1;
	lnt ans = 0;
	while(!que.empty()){
		plnt p = que.front(); que.pop();
		lnt posx = p.first, posy = p.second;
		// cerr << '(' << posx << ", " << posy << ')'<< ln;
		if(posx == 0 or posx == tatesiz-2 or posy == 0 or posy == yokosiz-2){
			cout << "INF" << ln;
			return 0;
		}
		lnt S = field[posx][posy].first.second-field[posx][posy].first.first;
		S *= (field[posx][posy].second.second-field[posx][posy].second.first);
		ans += S;
		REP(i, 4){
			lnt nxx = posx+dx[i], nxy = posy+dy[i];
			if(visit[nxx][nxy]) continue;
			if(nxx < 0 or tatesiz-1 <= nxx or nxy < 0 or yokosiz-1 <= nxy) continue;
			if(posx == nxx){
				lnt J = field[posx][posy].first.first;
				J = tate[J];
				if(nxy < posy and tateimos[posy][J]) continue;
				if(posy < nxy and tateimos[nxy][J]) continue;
			} else {
				lnt I = field[posx][posy].second.first;
				I = yoko[I];
				if(nxx < posx and yokoimos[posx][I]) continue;
				if(posx < nxx and yokoimos[nxx][I]) continue;
			}
			que.push({nxx, nxy});
			visit[nxx][nxy] = 1;
		}
	}
	cout << ans << ln;
}

Measured memory_bytes: 428220