#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
 
struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;
 
template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
    os<<p.first<<" "<<p.second;
    return os;
}
 
template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is,pair<T1,T2>&p){
    is>>p.first>>p.second;
    return is;
}

template<typename T>
istream &operator>>(istream &is,vector<T>&v){
    for(T &x:v)is>>x;
    return is;
}


signed main(){
    int n,m;cin>>n>>m;
    vector<ll> a(n),b(n),c(n),d(m),e(m),f(m),xs={-LINF,LINF},ys={-LINF,LINF};
    rep(i,n){
        cin>>a[i]>>b[i]>>c[i];
        xs.push_back(a[i]);
        xs.push_back(b[i]);
        ys.push_back(c[i]);
    }
    rep(i,m){
        cin>>d[i]>>e[i]>>f[i];
        xs.push_back(d[i]);
        ys.push_back(e[i]);
        ys.push_back(f[i]);
    }

    sort(ALL(xs));
    sort(ALL(ys));
    xs.erase(unique(ALL(xs)),end(xs));
    ys.erase(unique(ALL(ys)),end(ys));
    
    int w=(int)xs.size()-1,h=(int)ys.size()-1;

    vector<vector<bool>> ri(h,vector<bool>(w,false)),le(h,vector<bool>(w,false)),up(h,vector<bool>(w,false)),dw(h,vector<bool>(w,false));
    vector<vector<ll>> s(h,vector<ll>(w));

    rep(i,h)rep(j,w){
        if(i==0 or i==h-1 or j==0 or j==w-1) s[i][j]=-1;
        else s[i][j]=(ys[i+1]-ys[i])*(xs[j+1]-xs[j]);
    }
    

    rep(i,n){
        int xl=a[i],xr=b[i],y=c[i];
        auto yi=lower_bound(ALL(ys),y)-begin(ys);
        auto xli=lower_bound(ALL(xs),xl)-begin(xs);
        auto xri=lower_bound(ALL(xs),xr)-begin(xs);
        for(int x=xli;x<xri;x++){
            up[yi][x]=true;
            dw[yi-1][x]=true;
        }   
    }

    rep(j,m){
        int yl=e[j],yr=f[j],x=d[j];
        auto xi=lower_bound(ALL(xs),x)-begin(xs);
        auto yli=lower_bound(ALL(ys),yl)-begin(ys);
        auto yri=lower_bound(ALL(ys),yr)-begin(ys);
        for(int y=yli;y<yri;y++){
            le[y][xi]=true;
            ri[y][xi-1]=true;
        }
    }



    ll res=0;
    vector<vector<bool>> check(h,vector<bool>(w,false));
    int sj=lower_bound(ALL(xs),0)-begin(xs),si=lower_bound(ALL(ys),0)-begin(ys);
    sj--,si--;

    queue<pair<int,int>> que;
    que.push({si,sj});

    while(!que.empty()){
        auto [i,j]=que.front();que.pop();
        if(check[i][j]) continue;
        res+=s[i][j];
        check[i][j]=true;
        if(!up[i][j]){
            if(s[i-1][j]==-1){
                cout<<"INF"<<endl;
                return 0;
            }
            que.push({i-1,j});
        }
        if(!dw[i][j]){
            if(s[i+1][j]==-1){
                cout<<"INF"<<endl;
                return 0;
            }
            que.push({i+1,j});
        }
        if(!ri[i][j]){
            if(s[i][j+1]==-1){
                cout<<"INF"<<endl;
                return 0;
            }
            que.push({i,j+1});
        }
        if(!le[i][j]){
            if(s[i][j-1]==-1){
                cout<<"INF"<<endl;
                return 0;
            }
            que.push({i,j-1});
        }
    }
    cout<<res<<endl;

    // rep(i,h){
    //     rep(j,w){
    //         cout<<s[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    // rep(i,h){
    //     rep(j,w){
    //         cout<<check[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }

    // cout<<"RI"<<endl;
    // rep(i,h){
    //     rep(j,w){
    //         cout<<ri[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    // cout<<"LE"<<endl;
    // rep(i,h){
    //     rep(j,w){
    //         cout<<le[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    // cout<<"UP"<<endl;
    // rep(i,h){
    //     rep(j,w){
    //         cout<<up[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    // cout<<"DW"<<endl;
    // rep(i,h){
    //     rep(j,w){
    //         cout<<dw[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    return 0;
}


/*

3 3
-1 1 1
-1 0 -1
0 1 -2
-1 -1 1
0 -2 -1
1 -2 1


*/

Measured memory_bytes: 80028