#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=3005;
int a[MAXN],b[MAXN],c[MAXN],d[MAXN],e[MAXN],f[MAXN],x[MAXN],y[MAXN];
bool dw[MAXN][MAXN],lef[MAXN][MAXN],vis[MAXN][MAXN];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    int cntx=0,cnty=0;
    x[++cntx]=0,y[++cnty]=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d%d",&a[i],&b[i],&c[i]);
        x[++cntx]=a[i],x[++cntx]=b[i],y[++cnty]=c[i];
    }
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d%d",&d[i],&e[i],&f[i]);
        x[++cntx]=d[i],y[++cnty]=e[i],y[++cnty]=f[i];
    }

    /// pre-process
    sort(x+1,x+cntx+1);
    cntx=unique(x+1,x+cntx+1)-(x+1);
    sort(y+1,y+cnty+1);
    cnty=unique(y+1,y+cnty+1)-(y+1);
//    printf("%d %d\n",cntx,cnty);
//    for(int i=1;i<=cntx;i++)
//        printf("%d ",x[i]);
//    printf("\n");
//    for(int i=1;i<=cnty;i++)
//        printf("%d ",y[i]);
//    printf("\n");
    for(int i=1;i<=n;i++)
    {
        a[i]=lower_bound(x+1,x+cntx+1,a[i])-x;
        b[i]=lower_bound(x+1,x+cntx+1,b[i])-x;
        c[i]=lower_bound(y+1,y+cnty+1,c[i])-y;
        for(int j=a[i];j<b[i];j++)
            dw[j][c[i]]=1;
    }
    for(int i=1;i<=m;i++)
    {
        d[i]=lower_bound(x+1,x+cntx+1,d[i])-x;
        e[i]=lower_bound(y+1,y+cnty+1,e[i])-y;
        f[i]=lower_bound(y+1,y+cnty+1,f[i])-y;
        for(int j=e[i];j<f[i];j++)
            lef[d[i]][j]=1;
    }

    /// bfs
    int sx=lower_bound(x+1,x+cntx+1,0)-x;
    int sy=lower_bound(y+1,y+cnty+1,0)-y;
    queue<pair<int,int>>q;
    q.push({sx,sy});
    while(!q.empty())
    {
        int nx,ny;
        tie(nx,ny)=q.front();
        q.pop();
        if(vis[nx][ny])continue;
//        printf("%d %d\n",nx,ny);
        vis[nx][ny]=1;
        /// dw
        if(ny>0 && !dw[nx][ny])
            q.push({nx,ny-1});
        /// lef
        if(nx>0 && !lef[nx][ny])
            q.push({nx-1,ny});
        /// up
        if(ny<cnty && !dw[nx][ny+1])
            q.push({nx,ny+1});
        /// rig
        if(nx<cntx && !lef[nx+1][ny])
            q.push({nx+1,ny});
    }

    /// cal answer
    ll res=0;
    for(int i=0;i<=cntx;i++)
        for(int j=0;j<=cnty;j++)if(vis[i][j])
        {
            if(i==0 || i==cntx || j==0 || j==cnty)
                return 0*printf("INF\n");
            res+=1LL*(x[i+1]-x[i])*(y[j+1]-y[j]);
        }
    return 0*printf("%lld\n",res);
}
/*
2 2
-1 1 -1
-1 1 1
-1 -1 1
1 -1 1
*/
