#include<queue>
#include<cctype>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
using i64=long long;
using pi=pair<int,int>;
int read(){int x=0,c=getchar(),f=1;while(isspace(c))c=getchar();if(c=='-')f=-1,c=getchar();while(isdigit(c))(x*=10)+=c&15,c=getchar();return f*x;}
const int N=3007,dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
int n,m,cx,cy,nx,ny,px[N],py[N],vis[N][N],id[N][N],ban[N][N][4];queue<pi>q;
struct line1{int a,b,c;}l1[N];
struct line2{int a,b,c;}l2[N];
pi get(int x){return pi(x/cx,x%cx);}
int main()
{
    n=read(),m=read();i64 ans=0,inf=1300000000,flg=0;
    px[cx++]=-inf,py[cy++]=-inf,px[cx++]=inf,py[cy++]=inf;
    for(int i=1;i<=n;++i)
    {
	int a=read(),b=read(),c=read();
	l1[i]={a,b,c};
	px[cx++]=a,px[cx++]=b,py[cy++]=c;
    }
    for(int i=1;i<=m;++i)
    {
	int a=read(),b=read(),c=read();
	l2[i]={a,b,c};
	px[cx++]=a,py[cy++]=b,py[cy++]=c;
    }
    sort(px,px+cx),sort(py,py+cy);
    for(int i=1;i<=n;++i) l1[i].a=lower_bound(px,px+cx,l1[i].a)-px,l1[i].b=lower_bound(px,px+cx,l1[i].b)-px,l1[i].c=lower_bound(py,py+cy,l1[i].c)-py;
    for(int i=1;i<=m;++i) l2[i].a=lower_bound(px,px+cx,l2[i].a)-px,l2[i].b=lower_bound(py,py+cy,l2[i].b)-py,l2[i].c=lower_bound(py,py+cy,l2[i].c)-py;
    for(int i=0;i<cx;++i) if(px[i]<=0&&px[i+1]>0) nx=i;
    for(int i=0;i<cy;++i) if(py[i]<=0&&py[i+1]>0) ny=i;
    for(int i=1;i<=n;++i)
    {
	int a=l1[i].a,b=l1[i].b,c=l1[i].c;
	for(int j=a;j<b;++j) ban[j][c-1][2]=ban[j][c][3]=1;
    }
    for(int i=1;i<=m;++i)
    {
	int a=l2[i].a,b=l2[i].b,c=l2[i].c;
	for(int j=b;j<c;++j) ban[a-1][j][0]=ban[a][j][1]=1;
    }
    vis[nx][ny]=1,q.emplace(nx,ny);
    for(;!q.empty();)
    {
	pi t=q.front();q.pop();
	int x=t.first,y=t.second;
	for(int k=0;k<4;++k)
	    if(!ban[x][y][k])
	    {
		int sx=x+dx[k],sy=y+dy[k];
		if(sx<0||sy<0||sx>=cx||sy>=cy) continue;
		if(!vis[sx][sy]) vis[sx][sy]=1,q.emplace(sx,sy);
	    }
    }
    for(int i=0;i<cx;++i) for(int j=0;j<cy;++j) if(vis[i][j]) ans+=1ll*(px[i+1]-px[i])*(py[j+1]-py[j]);
    for(int i=0;i<cx;++i) if(vis[i][0]||vis[i][cy-1]) flg=1;
    for(int i=0;i<cy;++i) if(vis[0][i]||vis[cx-1][i]) flg=1;
    if(flg) return puts("INF"),0;
    printf("%lld",ans);
}
