#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;

int n,m;

vector<ll> lshx,lshy;
ll A[1100],B[1100],C[1100];
ll D[1100],E[1100],F[1100];
inline ll findx(ll v)
{
	return lower_bound(lshx.begin(),lshx.end(),v)-lshx.begin();
}
inline ll findy(ll v)
{
	return lower_bound(lshy.begin(),lshy.end(),v)-lshy.begin();
}
int blx[5500][5500],bly[5500][5500],vis[5500][5500];
queue<pii> que;
ll ans=0;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
	{
		scanf("%lld%lld%lld",&A[i],&B[i],&C[i]);
		lshx.push_back(A[i]);
		lshx.push_back(B[i]);
		lshy.push_back(C[i]);
	}
	for(int i=0;i<m;i++)
	{
		scanf("%lld%lld%lld",&D[i],&E[i],&F[i]);
		lshx.push_back(D[i]);
		lshy.push_back(E[i]);
		lshy.push_back(F[i]);
	}
	lshx.push_back(0);
	lshx.push_back(-inf);
	lshx.push_back(inf);
	
	lshy.push_back(0);
	lshy.push_back(-inf);
	lshy.push_back(inf);
	
	sort(lshx.begin(),lshx.end());
	lshx.erase(unique(lshx.begin(),lshx.end()),lshx.end());
	sort(lshy.begin(),lshy.end());
	lshy.erase(unique(lshy.begin(),lshy.end()),lshy.end());
	for(int i=0;i<n;i++)
	{
		A[i]=findx(A[i]);
		B[i]=findx(B[i]);
		C[i]=findy(C[i]);
	}
	for(int i=0;i<m;i++)
	{
		D[i]=findx(D[i]);
		E[i]=findy(E[i]);
		F[i]=findy(F[i]);
	}
	for(int i=0;i<n;i++)
	{
		bly[A[i]][C[i]]++;
		bly[B[i]][C[i]]--;
	}
	for(int i=0;i<m;i++)
	{
		blx[D[i]][E[i]]++;
		blx[D[i]][F[i]]--;
	}
	n=lshx.size();
	m=lshy.size();
	for(int i=1;i<n;i++)
	{
		for(int j=1;j<m;j++)
		{
			blx[i][j]+=blx[i][j-1];
			bly[i][j]+=bly[i-1][j];
		}
	}
	que.push(make_pair(findx(0),findy(0)));
	while(!que.empty())
	{
		int xx=que.front().first;
		int yy=que.front().second;
	//	cout<<xx<<" "<<yy<<endl;
		que.pop();
		if(xx==0||yy==0||xx==n-1||yy==m-1)
		{
			printf("INF\n");
			return 0;
		}
		if(vis[xx][yy])continue;
		vis[xx][yy]=1;
		ans+=(lshx[xx+1]-lshx[xx])*1ll*(lshy[yy+1]-lshy[yy]);
		if(!blx[xx][yy])que.push(make_pair(xx-1,yy));
		if(!bly[xx][yy])que.push(make_pair(xx,yy-1));
		if(!blx[xx+1][yy])que.push(make_pair(xx+1,yy));
		if(!bly[xx][yy+1])que.push(make_pair(xx,yy+1));
	}
	printf("%lld\n",ans);
	return 0;
}