#include<bits/stdc++.h>
using namespace std;

#define     MX        100005
#define     mod       1000000007
#define     ll        long long
#define     ld        double
#define     mem(a,b)  memset(a,b,sizeof(a))
#define     fast()    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     F         first
#define     S         second
#define     mp        make_pair
#define     inf       2e18
#define     PI        acos(-1.0)

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

set<ll>xST;
set<ll>yST;
map<ll,ll>xMP;
map<ll,ll>yMP;
ll A[1005],B[1005],C[1005];
ll D[1005],E[1005],F[1005];
ll n,m;
ll ex,wye;

struct data{
    ll khetro;
    bool s[4];
}grid[4005][4005];
bool vis[4005][4005];

long long DFS(int ro,int col){
    //cout<<"DFS "<<ro<< " "<<col<<" "<<grid[ro][col].khetro<<endl;
    //cout<<ex<<" "<<wye<<endl;
    if(ro<=0 ||  ro>ex) return -1;
    if(col<=0 || col>wye) return -1;

    if(vis[ro][col]) return 0LL;
    vis[ro][col]=true;
    ll area=0;
    if(grid[ro][col].s[0]){
        //cout<<"up"<<endl;
        ll got = DFS(ro,col+1);
        if(got==-1) return -1;
        area+=got;
    }
    if(grid[ro][col].s[1]){
        //cout<<"down"<<endl;
        ll got= DFS(ro,col-1);
        if(got==-1) return -1;
        area+=got;
    }
    if(grid[ro][col].s[2]){
        //cout<<"right"<<endl;
        ll got= DFS(ro+1,col);
        if(got==-1) return -1;
        area+=got;
    }
    if(grid[ro][col].s[3]){
        //cout<<"left"<<endl;
        ll got = DFS(ro-1,col);
        if(got==-1) return -1;
        area+=got;
    }
    area+=grid[ro][col].khetro;
    return area;
}

int main(){
    fast();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin>>n;
    cin>>m;
    for(int i=1;i<=n;i++){
        cin>>A[i]>>B[i]>>C[i];
        xST.insert(A[i]);
        xST.insert(B[i]);
        xST.insert(B[i]-1);
        yST.insert(C[i]);
    }
    for(int i=1;i<=m;i++){
        cin>>D[i]>>E[i]>>F[i];
        xST.insert(D[i]);
        yST.insert(E[i]);
        yST.insert(F[i]);
        yST.insert(F[i]-1);
    }
    xST.insert(0);
    xST.insert(-2e9);
    xST.insert(+2e9);
    yST.insert(0);
    yST.insert(-2e9);
    yST.insert(+2e9);

    ex= xST.size();
    wye= yST.size();
    //cout<<"siz "<<xST.size()<<endl;
    //cout<<"siz "<<yST.size()<<endl;

    int now=0;
    for(auto it=xST.begin();it!=xST.end();it++){
        xMP[*it]=now++;
        //cout<<*it<<" "<<xMP[*it]<<endl;
    }
    //cout<<"lol"<<endl;
    now=0;
    for(auto it=yST.begin();it!=yST.end();it++){
        yMP[*it]=now++;
        //cout<<*it<<" "<<yMP[*it]<<endl;
    }


    ///Making grid
    ll bx,by;
    for(auto xit= xST.begin();xit!=xST.end();xit++){
        if(xit==xST.begin()){
            bx= *xit;
            continue;
        }
        for(auto yit = yST.begin();yit!=yST.end();yit++){
            if(yit==yST.begin()){
                by=*yit;
                continue;
            }
            int nx=xMP[*xit];
            int ny=yMP[*yit];
            grid[nx][ny].khetro= 1LL*(*xit-bx)*(*yit-by);
            for(int i=0;i<4;i++) grid[nx][ny].s[i]=true;
            by=*yit;

            //cout<<"cell "<<nx<<" "<<ny<<" "<<grid[nx][ny].khetro<<endl;
        }
        bx=*xit;
    }

    ///Drawing Bound for parallel lines with x axis
    for(int i=1;i<=n;i++){
        int nx,ny=yMP[C[i]]+1;
        for(int j=xMP[A[i]];j<xMP[B[i]];j++){
            nx=j+1;
            grid[nx][ny].s[1]=false;
            if((ny-1>0)) grid[nx][ny-1].s[0]=false;
        }
    }
    ///Drawing Bound for parallel lines with y axis
    for(int i=1;i<=m;i++){
        int nx=xMP[D[i]]+1,ny;
        for(int j=yMP[E[i]];j<yMP[F[i]];j++){
            ny=j+1;
            grid[nx][ny].s[3]=false;
            if((nx-1>0)) grid[nx-1][ny].s[2]=false;
        }
    }
    ll ans=DFS(xMP[0],yMP[0]);
    if(ans==-1) cout<<"INF"<<endl;
    else cout<<ans<<endl;
}
