//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

//////////////////////////

ll dx[4]={0,1,-1,0};
ll dy[4]={1,0,0,-1};
void no(){
    cout<<"INF"<<endl;
    exit(0);
}


ll mp[7000][7000];

int main(){fastio
    ll n,m;cin>>n>>m;
    ll a[n],b[n],c[n];
    ll d[m],e[m],f[m];
    rep(i,0,n-1)cin>>a[i]>>b[i]>>c[i];
    rep(i,0,m-1)cin>>d[i]>>e[i]>>f[i];
    vector<ll>x,y;
    x.pb(-inf);x.pb(inf);y.pb(-inf);y.pb(inf);
    x.pb(0);y.pb(0);
    rep(i,0,n-1){
        x.pb(a[i]);x.pb(b[i]);
        y.pb(c[i]);
    }
    rep(i,0,m-1){
        x.pb(d[i]);
        y.pb(e[i]);y.pb(f[i]);
    }
    SORT(x);ERASE(x);
    SORT(y);ERASE(y);
    rep(i,0,n-1){
        a[i]=POSL(x,a[i]);
        b[i]=POSL(x,b[i]);
        c[i]=POSL(y,c[i]);
    }
    rep(i,0,m-1){
        d[i]=POSL(x,d[i]);
        e[i]=POSL(y,e[i]);
        f[i]=POSL(y,f[i]);
    }
    ll xs=x.size();
    ll ys=y.size();
    vector<l_l>ty[ys];
    vector<l_l>tx[xs];
    rep(i,0,n-1){
        ty[c[i]].pb({a[i],b[i]});
    }
    rep(i,0,m-1){
        tx[d[i]].pb({e[i],f[i]});
    }
    rep(i,0,n-1){
        ll C=c[i]*2+1;
        ll A=a[i]*2+1;
        ll B=b[i]*2+1;
        rep(j,A,B){
            mp[j][C]=-1;
        }
    }
    rep(i,0,m-1){
        ll D=d[i]*2+1;
        ll E=e[i]*2+1;
        ll F=f[i]*2+1;
        rep(j,E,F){
            mp[D][j]=-1;
        }
    }
    ll stax=POSL(x,0)*2;
    ll stay=POSL(y,0)*2;
    queue<l_l>q;q.push({stax,stay});
    mp[stax][stay]=1;
    while(!q.empty()){
        l_l pos=q.front();q.pop();
        ll posx=pos.fi;
        ll posy=pos.se;
        rep(z,0,3){
            ll newx=posx+dx[z];
            ll newy=posy+dy[z];
            if(0<=newx&&newx<=2*xs){
                if(0<=newy&&newy<=2*ys){
                    if(mp[newx][newy]==0){
                        mp[newx][newy]=1;
                        q.push({newx,newy});
                    }
                }
            }
            
        }
    }
    /*
    rep(i,0,2*xs){
        rep(j,0,2*ys){
            cout<<mp[i][j]<<" ";
        }cout<<endl;
    }cout<<endl;
     */
    rep(i,0,2*ys){
        if(mp[0][i]==1)no();
        if(mp[2*xs][i]==1)no();
    }
    rep(i,0,2*xs){
        if(mp[i][0]==1)no();
        if(mp[i][2*ys]==1)no();
    }
    ll ans=0;
    rep(i,0,xs-2){
        rep(j,0,ys-2){
            ll ax=x[i];
            ll bx=x[i+1];
            ll ay=y[j];
            ll by=y[j+1];
            if(mp[i*2+2][j*2+2]==1){
                ans+=(by-ay)*(bx-ax);
            }
        }
    }
    cout<<ans<<endl;
    
    
    return 0;
}


Measured memory_bytes: 309412