#include <cstdio>
#include <algorithm>
#define LL long long
#define INF 2000000000
#define maxn 1010
using namespace std;
int n,m;
int k[][2]={{-1,0},{1,0},{0,-1},{0,1}};//L,R,U,D
int border[maxn][maxn][4];//边界
int vis[maxn][maxn],qx[maxn*maxn],qy[maxn*maxn];
LL ans;
struct node{
	int a,b,c;
}f[maxn],g[maxn];
int X[maxn],Y[maxn],XN,YN;
int findX(int v){
	return lower_bound(X,X+XN,v)-X;
}
int findY(int v){
	return lower_bound(Y,Y+YN,v)-Y;
}
void bfs(int xx,int yy){
	//printf("xx=%d yy=%d\n",xx,yy);
	int i,h,t,nx,ny,x,y;
	h=t=0;
	qx[t]=xx,qy[t]=yy,t++,vis[xx][yy]=1;
	while(h<t){
		x=qx[h],y=qy[h],h++;
		//printf("x=%d y=%d\n",x,y);
		ans+=(LL)(X[x+1]-X[x])*(Y[y+1]-Y[y]);
		//printf("ans=%lld\n",ans);
		for(i=0;i<4;i++){
			//printf("border[%d][%d][%d]=%d\n",x,y,i,border[x][y][i]);
			if(border[x][y][i])continue;
			nx=x+k[i][0],ny=y+k[i][1];
			//printf("border[%d][%d][%d]=%d nx=%d ny=%d\n",x,y,i,border[x][y][i],nx,ny);
			if(nx==0||nx==XN-1||ny==0||ny==YN-1){
				ans=-1;
				return;
			}
			if(vis[nx][ny])continue;
			//printf("x=%d y=%d i=%d nx=%d ny=%d\n",x,y,i,nx,ny),
			vis[nx][ny]=1,qx[t]=nx,qy[t]=ny,t++;
		}
	}
}
void init(){
	int i,x,y,r,j;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)scanf("%d%d%d",&f[i].a,&f[i].b,&f[i].c),X[XN++]=f[i].c;
	X[XN++]=-INF,X[XN++]=INF;
	sort(X,X+XN);//自小到大排序
	XN=unique(X,X+XN)-X;//去重
	for(i=0;i<m;i++)scanf("%d%d%d",&g[i].a,&g[i].b,&g[i].c),Y[YN++]=g[i].a;
	Y[YN++]=-INF,Y[YN++]=INF;
	sort(Y,Y+YN);//自小到大排序
	YN=unique(Y,Y+YN)-Y;
	/*printf("X: ");
	for(i=0;i<XN;i++)printf("%d ",X[i]);
	printf("\n");
	printf("Y: ");
	for(i=0;i<YN;i++)printf("%d ",Y[i]);
	printf("\n");*/
	for(i=0;i<n;i++){
		x=findX(f[i].c);
		r=findY(f[i].b);
		if(Y[r]!=f[i].b)r--;
		for(j=findY(f[i].a);j<r;j++)
			border[x-1][j][1]=border[x][j][0]=1;//,printf("border[%d][%d][%d]=%d border[%d][%d][%d]=%d\n",x-1,j,1,border[x-1][j][1],x,j,0,border[x][j][0]);//边界设定
	}
	for(i=0;i<m;i++){
		y=findY(g[i].a);
		r=findX(g[i].c);
		if(X[r]!=g[i].c)r--;
		for(j=findX(g[i].b);j<r;j++)
			border[j][y-1][3]=border[j][y][2]=1;//,printf("border[%d][%d][%d]=%d border[%d][%d][%d]=%d\n",j,y-1,3,border[j][y-1][3],j,y,2,border[j][y][2]);//边界设定
	}
}
int main(){
	init();
	bfs(findX(0)-1,findY(0)-1);
	if(ans==-1)printf("INF\n");
	else printf("%lld\n",ans);
	return 0;
}