#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int dx[4]={0,-1,0,1};
int dy[4]={1,0,-1,0};
int n,m;
int fie[6105][6105];
vector<int> xi;
vector<int> yi;
int a[1005],b[1005],c[1005];
int d[1005],e[1005],f[1005];

bool isInf(){
	for(int i=0;i<=yi.size()*2;i++){
		if(fie[i][0]==1 || fie[i][xi.size()*2]==1){
			return true;
		}
	}
	for(int i=0;i<=xi.size()*2;i++){
		if(fie[0][i]==1 || fie[yi.size()*2][i]==1){
			return true;
		}
	}
	return false;
}

int main(void){
	scanf("%d%d",&n,&m);
	xi.push_back(0);
	yi.push_back(0);
	for(int i=0;i<n;i++){
		scanf("%d%d%d",&a[i],&b[i],&c[i]);
		xi.push_back(a[i]);
		xi.push_back(b[i]);
		yi.push_back(c[i]);
	}
	for(int i=0;i<m;i++){
		scanf("%d%d%d",&d[i],&e[i],&f[i]);
		xi.push_back(d[i]);
		yi.push_back(e[i]);
		yi.push_back(f[i]);
	}
	sort(xi.begin(),xi.end());
	xi.erase(unique(xi.begin(),xi.end()),xi.end());
	sort(yi.begin(),yi.end());
	yi.erase(unique(yi.begin(),yi.end()),yi.end());
	for(int i=0;i<n;i++){
		int lx=lower_bound(xi.begin(),xi.end(),a[i])-xi.begin();
		lx=lx*2+1;
		int rx=lower_bound(xi.begin(),xi.end(),b[i])-xi.begin();
		rx=rx*2+1;
		int y=lower_bound(yi.begin(),yi.end(),c[i])-yi.begin();
		y=y*2+1;
		for(int i=lx;i<=rx;i++){
			fie[y][i]=-1;
		}
	}
	for(int i=0;i<m;i++){
		int x=lower_bound(xi.begin(),xi.end(),d[i])-xi.begin();
		x=x*2+1;
		int ly=lower_bound(yi.begin(),yi.end(),e[i])-yi.begin();
		ly=ly*2+1;
		int ry=lower_bound(yi.begin(),yi.end(),f[i])-yi.begin();
		ry=ry*2+1;
		for(int i=ly;i<=ry;i++){
			fie[i][x]=-1;
		}
	}
	queue<P> que;
	int sx=lower_bound(xi.begin(),xi.end(),0)-xi.begin();
	int sy=lower_bound(yi.begin(),yi.end(),0)-yi.begin();
	sx=sx*2+1;
	sy=sy*2+1;
	que.push(P(sx,sy));
	fie[sy][sx]=1;
	while(que.size()){
		P p=que.front();
		que.pop();
		int cx=p.first;
		int cy=p.second;
		for(int i=0;i<4;i++){
			int nx=cx+dx[i];
			int ny=cy+dy[i];
			if(ny<0 || ny>yi.size()*2 || nx<0 || nx>xi.size()*2){
				continue;
			}
			if(fie[ny][nx]==0){
				fie[ny][nx]=1;
				que.push(P(nx,ny));
			}
		}
	}
	if(isInf()){
		printf("INF\n");
		return 0;
	}
	ll ans=0;
	for(int i=0;i+1<yi.size();i++){
		for(int j=0;j+1<xi.size();j++){
			if(fie[i*2+2][j*2+2]==1){
				ll dx=xi[j+1]-xi[j];
				ll dy=yi[i+1]-yi[i];
				ans+=dx*dy;
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}
