#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=3005;
int n,m;
int a[max_n],b[max_n],c[max_n],d[max_n],e[max_n],f[max_n];
vector<int> x,y;
int gx(int ox){
    return lower_bound(x.begin(),x.end(),ox)-x.begin()+1;
}
int gy(int oy){
    return lower_bound(y.begin(),y.end(),oy)-y.begin()+1;
}
bool vis[max_n][max_n],dwn[max_n][max_n],lef[max_n][max_n];
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d%d%d",a+i,b+i,c+i);
        x.push_back(a[i]),x.push_back(b[i]),y.push_back(c[i]);
    }
    for(int i=1;i<=m;i++){
        scanf("%d%d%d",d+i,e+i,f+i);
        x.push_back(d[i]),y.push_back(e[i]),y.push_back(f[i]);
    }
    x.push_back(0),y.push_back(0);
    sort(x.begin(),x.end());x.erase(unique(x.begin(),x.end()),x.end());
    sort(y.begin(),y.end());y.erase(unique(y.begin(),y.end()),y.end());
    for(int i=1;i<=n;i++){
        a[i]=gx(a[i]),b[i]=gx(b[i]),c[i]=gy(c[i]);
        for(int j=a[i];j<b[i];j++)dwn[j][c[i]]=true;
    }
    for(int i=1;i<=m;i++){
        d[i]=gx(d[i]),e[i]=gy(e[i]),f[i]=gy(f[i]);
        for(int j=e[i];j<f[i];j++)lef[d[i]][j]=true;
    }
    int ox=0,oy=0;
    ox=gx(ox),oy=gy(oy);
    #define P pair<int,int> 
    queue<P> que;
    que.push(P(ox,oy));
    vis[ox][oy]=true;
    ll ans=0;
    while(!que.empty()){
        P p=que.front();que.pop();
        ox=p.first,oy=p.second;
        if(ox==0||ox==x.size()||oy==0||oy==y.size())return printf("INF\n"),0;
        ans+=1ll*(x[ox]-x[ox-1])*(y[oy]-y[oy-1]);
        //left
        if(ox&&!lef[ox][oy]&&!vis[ox-1][oy]){
            vis[ox-1][oy]=true;
            que.push(P(ox-1,oy));
        }
        //right
        if(ox+1<=x.size()&&!lef[ox+1][oy]&&!vis[ox+1][oy]){
            vis[ox+1][oy]=true;
            que.push(P(ox+1,oy));
        }
        //up
        if(oy+1<=y.size()&&!dwn[ox][oy+1]&&!vis[ox][oy+1]){
            vis[ox][oy+1]=true;
            que.push(P(ox,oy+1));
        }
        //down
        if(oy&&!dwn[ox][oy]&&!vis[ox][oy-1]){
            vis[ox][oy-1]=true;
            que.push(P(ox,oy-1));
        }
    }
    printf("%lld\n",ans);
    return 0;
}
