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

#define     MX        100005
#define     mod       1000000007
#define     ll        long long
#define     ld        double
#define     mem(a,b)  memset(a,b,sizeof(a))
#define     fast()    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     F         first
#define     S         second
#define     mp        make_pair
#define     inf       1000000010
#define     PI        acos(-1.0)

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

set<ll>xST;
set<ll>yST;
map<ll, ll>xMP;
map<ll, ll>yMP;
ll A[1005], B[1005], C[1005];
ll D[1005], E[1005], F[1005];
ll n, m;
ll ex, wye;

struct data{
	ll khetro;
	bool s[4];
}grid[4005][4005];
bool vis[4005][4005];

ll DFS(ll ro, ll col){

	//cout<<ex<<" "<<wye<<endl;
	if (ro <= 1 || ro >= ex) return -1;
	if (col <= 1 || col >= wye) return -1;
	//cout << "DFS " << ro << " " << col << " " << grid[ro][col].khetro << endl;

	if (vis[ro][col]) return 0LL;
	vis[ro][col] = true;
	ll area = 0;
	if (grid[ro][col].s[0]){
		//cout<<"up"<<endl;
		ll got = DFS(ro, col + 1);
		if (got == -1) return -1;
		else area += got;
	}
	if (grid[ro][col].s[1]){
		//cout<<"down"<<endl;
		ll got = DFS(ro, col - 1);
		if (got == -1) return -1;
		area += got;
	}
	if (grid[ro][col].s[2]){
		//cout<<"right"<<endl;
		ll got = DFS(ro + 1, col);
		if (got == -1) return -1;
		area += got;
	}
	if (grid[ro][col].s[3]){
		//cout<<"left"<<endl;
		ll got = DFS(ro - 1, col);
		if (got == -1) return -1;
		area += got;
	}
	area += grid[ro][col].khetro;
	return area;
}

int main(){
	fast();
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin >> n;
	cin >> m;
	for (int i = 1; i <= n; i++){
		cin >> A[i] >> B[i] >> C[i];
		xST.insert(A[i]);
		xST.insert(B[i]);
		xST.insert(B[i] - 1);
		yST.insert(C[i]);
	}
	for (int i = 1; i <= m; i++){
		cin >> D[i] >> E[i] >> F[i];
		xST.insert(D[i]);
		yST.insert(E[i]);
		yST.insert(F[i]);
		yST.insert(F[i] - 1);
	}
	xST.insert(0);
	xST.insert(-inf);
	xST.insert(+inf);
	yST.insert(0);
	yST.insert(-inf);
	yST.insert(+inf);

	ex = xST.size();
	wye = yST.size();
	//cout<<"siz "<<xST.size()<<endl;
	//cout<<"siz "<<yST.size()<<endl;

	int now = 0;
	for (auto it = xST.begin(); it != xST.end(); it++){
		xMP[*it] = now++;
		//cout<<*it<<" "<<xMP[*it]<<endl;
	}
	//cout<<"lol"<<endl;
	now = 0;
	for (auto it = yST.begin(); it != yST.end(); it++){
		yMP[*it] = now++;
		//cout<<*it<<" "<<yMP[*it]<<endl;
	}
	//cout << "lol" << endl;

	///Making grid
	ll bx, by;
	for (auto xit = xST.begin(); xit != xST.end(); xit++){
		if (xit == xST.begin()){
			bx = *xit;
			//cout << "ok" << endl;
			continue;
		}
		//cout << *xit << endl;
		for (auto yit = yST.begin(); yit != yST.end(); yit++){
			if (yit == yST.begin()){
				by = *yit;
				continue;
			}
			ll nx = xMP[*xit];
			ll ny = yMP[*yit];
			grid[nx][ny].khetro = 1LL * (*xit - bx)*(*yit - by);
			for (int i = 0; i<4; i++) grid[nx][ny].s[i] = true;
			by = *yit;

			//cout<<"cell "<<nx<<" "<<ny<<" "<<grid[nx][ny].khetro<<endl;
		}
		bx = *xit;
		//cout << "bx "<<bx << " "<<xMP[*xit]<<endl;
	}
	//cout << "lol" << endl;


	///Drawing Bound for parallel lines with x axis
	for (int i = 1; i <= n; i++){
		ll nx, ny = yMP[C[i]] + 1;
		for (ll j = xMP[A[i]]; j<xMP[B[i]]; j++){
			nx = j + 1;
			grid[nx][ny].s[1] = false;
			if ((ny - 1>0)) grid[nx][ny - 1].s[0] = false;
		}
	}
	///Drawing Bound for parallel lines with y axis
	for (int i = 1; i <= m; i++){
		ll nx = xMP[D[i]] + 1, ny;
		for (ll j = yMP[E[i]]; j<yMP[F[i]]; j++){
			ny = j + 1;
			grid[nx][ny].s[3] = false;
			if ((nx - 1>0)) grid[nx - 1][ny].s[2] = false;
		}
	}
	//cout << "finish" << endl;
	ll ans = DFS(xMP[0], yMP[0]);
  	//cout<<"paisi"<<endl;	
  
	if (ans == -1) cout << "INF" << endl;
	else cout << ans << endl;
}
