#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

template<class T> void cc(vector<T> a,unordered_map<T,int>& nm,vector<int>& c){
    sort(a.begin(),a.end());
    fr(i,a.size()){
        if(i<a.size()-1&&a[i]==a[i+1]) continue;
        nm[a[i]]=c.size();
        c.emplace_back(a[i]);
    }
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    vector<int> a(n),b(n),c(n),d(m),e(m),f(m),v(2*n+m+1),h(n+2*m+1);
    fr(i,n){
        cin>>a[i]>>b[i]>>c[i];
        v[i]=a[i];
        v[i+n]=b[i];
        h[i]=c[i];
    }
    fr(i,m){
        cin>>d[i]>>e[i]>>f[i];
        v[i+n*2]=d[i];
        h[i+n]=e[i];
        h[i+n+m]=f[i];
    }
    unordered_map<int,int> nmv,nmh;
    vector<int> V,H;
    cc(v,nmv,V);cc(h,nmh,H);
    auto lv=vector(V.size(),vector<bool>(H.size()));
    auto lh=vector(V.size(),vector<bool>(H.size()));
    fr(i,n){
        a[i]=nmv[a[i]];
        b[i]=nmv[b[i]];
        c[i]=nmh[c[i]];
        for(int I=a[i];I<b[i];++I) lv[I][c[i]]=true;
    }
    fr(i,m){
        d[i]=nmv[d[i]];
        e[i]=nmh[e[i]];
        f[i]=nmh[f[i]];
        for(int J=e[i];J<f[i];++J) lh[d[i]][J]=true;
    }
    ll ans{};
    stack<pair<int,int>> st;
    st.emplace(nmv[0],nmh[0]);
    int limv=V.size()-1,limh=H.size()-1;
    auto vis=vector(limv,vector<bool>(limh));
    while(!st.empty()){
        auto[x,y]=st.top();st.pop();
        if(vis[x][y]) continue;
        vis[x][y]=true;
        ans+=(ll)(V[x+1]-V[x])*(H[y+1]-H[y]);
        if(x==0 and !lh[x][y]) return puts("INF"),0;
        if(y==0 and !lv[x][y]) return puts("INF"),0;
        if(x+1==limv and !lh[x+1][y]) return puts("INF"),0;
        if(y+1==limh and !lv[x][y+1]) return puts("INF"),0;
        if(x>0 and !vis[x-1][y] and !lh[x][y]) st.emplace(x-1,y);
        if(y>0 and !vis[x][y-1] and !lv[x][y]) st.emplace(x,y-1);
        if(x+1<limv and !vis[x+1][y] and !lh[x+1][y]) st.emplace(x+1,y);
        if(y+1<limh and !vis[x][y+1] and !lv[x][y+1]) st.emplace(x,y+1);
    }
    cout<<ans<<'\n';
}