#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int n,m;
int a[2000],b[2000],c[2000],d[2000],e[2000],f[2000];
int sum1[5000][5000],sum2[5000][5000];
int dist[5000][5000];

int lwb(vector<int>&v,int x){
	return lower_bound(v.begin(),v.end(),x)-v.begin();
}

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

int ok(int x,int y,int d){
	if(d==0){
		return sum2[x+1][y]==0;
	}
	else if(d==1){
		return sum2[x][y]==0;
	}
	else if(d==2){
		return sum1[x][y+1]==0;
	}
	else{
		return sum1[x][y]==0;
	}
}

int main(){
	cin>>n>>m;
	vector<int>xs,ys;
	xs.push_back(0);ys.push_back(0);
	xs.push_back(-2e9);xs.push_back(2e9);
	ys.push_back(-2e9);ys.push_back(2e9);
	rep(i,n){
		scanf("%d%d%d",&a[i],&b[i],&c[i]);
		xs.push_back(a[i]);
		xs.push_back(b[i]);
		ys.push_back(c[i]);
	}
	rep(i,m){
		scanf("%d%d%d",&d[i],&e[i],&f[i]);
		xs.push_back(d[i]);
		ys.push_back(e[i]);
		ys.push_back(f[i]);
	}
	sort(xs.begin(),xs.end());xs.erase(unique(xs.begin(),xs.end()),xs.end());
	sort(ys.begin(),ys.end());ys.erase(unique(ys.begin(),ys.end()),ys.end());
	rep(i,n){
		a[i]=lwb(xs,a[i]);
		b[i]=lwb(xs,b[i]);
		c[i]=lwb(ys,c[i]);
		sum1[a[i]][c[i]]++;
		sum1[b[i]][c[i]]--;
	}
	rep(i,m){
		d[i]=lwb(xs,d[i]);
		e[i]=lwb(ys,e[i]);
		f[i]=lwb(ys,f[i]);
		sum2[d[i]][e[i]]++;
		sum2[d[i]][f[i]]--;
	}
	rep(i,xs.size()+1){
		rep(j,ys.size()+1){
			if(i)sum1[i][j]+=sum1[i-1][j];
			if(j)sum2[i][j]+=sum2[i][j-1];
		}
	}
	queue<P>que;
	memset(dist,-1,sizeof(dist));
	int sx=lwb(xs,0),sy=lwb(ys,0);
	dist[sx][sy]=0;
	que.push(P(sx,sy));
	while(!que.empty()){
		P p=que.front();que.pop();
		rep(k,4){
			int nx=p.first+dx[k],ny=p.second+dy[k];
			if(0<=nx&&nx<xs.size()-1&&0<=ny&&ny<ys.size()-1&&dist[nx][ny]==-1&&ok(p.first,p.second,k)){
				dist[nx][ny]=dist[p.first][p.second]+1;
				que.push(P(nx,ny));
			}
		}
	}
	if(dist[0][0]!=-1){
		puts("INF");return 0;
	}
	ll ans=0;
	rep(i,xs.size()-1)rep(j,ys.size()-1){
		if(dist[i][j]!=-1){
			ll h=xs[i+1]-xs[i],w=ys[j+1]-ys[j];
			ans+=h*w;
		}
	}
	cout<<ans<<endl;
}