#include <algorithm>
#include <queue>
#include <cstdio>

using namespace std;

const int INF=1e9+5;

struct seg_t{
    int X;
    int Y;
    int Z;//level
};

int vertLen=0,horLen=0;
int N,M;
seg_t vert[1010],hor[1010];
int vertP[3010],horP[3010];
bool grid[3030][3030][4],visited[3030][3030];

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

int main(){
    scanf("%d%d",&N,&M);
    for(int i=0;i<N;i++){
        scanf("%d%d%d",&vert[i].X,&vert[i].Y,&vert[i].Z);
        vertP[vertLen++]=vert[i].X;
        vertP[vertLen++]=vert[i].Y;
        horP[horLen++]=vert[i].Z;   
    }

    for(int i=0;i<M;i++){
        scanf("%d%d%d",&hor[i].Z,&hor[i].X,&hor[i].Y);
        horP[horLen++]=hor[i].X;
        horP[horLen++]=hor[i].Y;
        vertP[vertLen++]=hor[i].Z;   
    }
    
    vertP[vertLen++]=INF;
    vertP[vertLen++]=0;
    vertP[vertLen++]=-INF;

    horP[horLen++]=INF;
    horP[horLen++]=0;
    horP[horLen++]=-INF;

    sort(horP,horP+horLen);
    sort(vertP,vertP+vertLen);
    horLen=unique(horP,horP+horLen)-horP-1;
    vertLen=unique(vertP,vertP+vertLen)-vertP-1;

    for(int i=0;i<N;i++){
        int l=lower_bound(vertP,vertP+vertLen,vert[i].X)-vertP;
        int r=lower_bound(vertP,vertP+vertLen,vert[i].Y)-vertP;
        int level=lower_bound(horP,horP+horLen,vert[i].Z)-horP;

        for(int j=l;j<r;j++){
            grid[j][level-1][0]=true;
            grid[j][level][2]=true;
        }
    }

    for(int i=0;i<M;i++){
        int l=lower_bound(horP,horP+horLen,hor[i].X)-horP;
        int r=lower_bound(horP,horP+horLen,hor[i].Y)-horP;
        int level=lower_bound(vertP,vertP+vertLen,hor[i].Z)-vertP;

        for(int j=l;j<r;j++){
            grid[level-1][j][1]=true;
            grid[level][j][3]=true;
        }
    }

    queue<pair<int,int>> q;
    auto sx=lower_bound(vertP,vertP+vertLen,0)-vertP,sy=lower_bound(horP,horP+horLen,0)-horP;
    q.push({sx,sy});
    visited[sx][sy]=true;
    bool closed=true;

    long long ans=0;

    while(!q.empty()){
        auto x=q.front().first,y=q.front().second;
        q.pop();

        
        if (x==0||x==vertLen-1||y==0||y==horLen-1){
            closed=false;
            break;
        }

        ans+=1ll*(vertP[x+1]-vertP[x])*(horP[y+1]-horP[y]);

        for(int k=0;k<4;k++){
            if (!grid[x][y][k]){
                auto px=x+dx[k],py=y+dy[k];
                if (px < 0 || px >= vertLen || py < 0 || py >= horLen || visited[px][py]) continue;
                q.push({px,py});
                visited[px][py]=true;
            }
        }
    }

    if (!closed) {
        puts("INF");
        return 0;
    }

    printf("%lld\n",ans);
    return 0;
}