#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};
 
const int N=3030;
struct ot{
    int x1,x2,y;
};
ot h[N],w[N];
int ax[N],ay[N],f[N][N],p[N*N],rk[N*N],ar[N*N];
bool inf[N*N];
int get(int x){return x==p[x]?x:(p[x]=get(p[x]));}
void un(int x,int y){
    if((x=get(x))==(y=get(y)))return;
    if(rk[x]<rk[y])swap(x,y);
    inf[x]|=inf[y];
    ar[x]+=ar[y];
    rk[x]+=(rk[x]==rk[y]);
    p[y]=x;
}
vector<pii> onx[N],ony[N];
int32_t main(){
    int n,m;
    cin>>n>>m;
    int xs=0,ys=0;
    forn(i,n){
        cin>>h[i].x1>>h[i].x2>>h[i].y;
        ax[xs++]=h[i].x1;
        ax[xs++]=h[i].x2;
        ay[ys++]=h[i].y;
    }
    forn(i,m){
        cin>>w[i].y>>w[i].x1>>w[i].x2;
        ay[ys++]=w[i].x1;
        ay[ys++]=w[i].x2;
        ax[xs++]=w[i].y;
    }
    sort(ax,ax+xs);
    xs=unique(ax,ax+xs)-ax;
    sort(ay,ay+ys);
    ys=unique(ay,ay+ys)-ay;
    forn(i,n){
        int x1=lower_bound(ax,ax+xs,h[i].x1)-ax;
        int x2=lower_bound(ax,ax+xs,h[i].x2)-ax;
        int y=lower_bound(ay,ay+ys,h[i].y)-ay;
        ony[y].pb(x1,x2);
    }
    forn(i,m){
        int y1=lower_bound(ay,ay+ys,w[i].x1)-ay;
        int y2=lower_bound(ay,ay+ys,w[i].x2)-ay;
        int x=lower_bound(ax,ax+xs,w[i].y)-ax;
        onx[x].pb(y1,y2);
    }
    if(xs<=1||ys<=1){
        cout<<"INF\n";
        return 0;
    }
    forn(i,xs)sort(onx[i].begin(), onx[i].end());
    forn(i,ys)sort(ony[i].begin(), ony[i].end());
    int z=0;
    forn(i,xs-1){
        forn(j,ys-1){
            f[i][j]=z;
            p[z]=z;
            rk[z]=0;
            ar[z]=(ax[i+1]-ax[i])*(ay[j+1]-ay[j]);
            inf[z]=0;
            z++;
        }
    }
    {
        int pr=0;
        for(pii p:onx[0]){
            int l=p.f,r=p.s;
            for(int j=pr;j<l;++j)inf[f[0][j]]=1;
            pr=r;
        }
        for(int j=pr;j<ys-1;++j)inf[f[0][j]]=1;
    }
    {
        int pr=0;
        for(pii p:onx[xs-1]){
            int l=p.f,r=p.s;
            for(int j=pr;j<l;++j)inf[f[xs-2][j]]=1;
            pr=r;
        }
        for(int j=pr;j<ys-1;++j)inf[f[xs-2][j]]=1;
    }
    {
        int pr=0;
        for(pii p:ony[0]){
            int l=p.f,r=p.s;
            for(int j=pr;j<l;++j)inf[f[j][0]]=1;
            pr=r;
        }
        for(int j=pr;j<xs-1;++j)inf[f[j][0]]=1;
    }
    {
        int pr=0;
        for(pii p:ony[ys-1]){
            int l=p.f,r=p.s;
            for(int j=pr;j<l;++j)inf[f[j][ys-2]]=1;
            pr=r;
        }
        for(int j=pr;j<xs-1;++j)inf[f[j][ys-2]]=1;
    }
    for(int i=1;i<xs-1;++i){
        int pr=0;
        for(pii p:onx[i]){
            int l=p.f,r=p.s;
            for(int j=pr;j<l;++j)un(f[i-1][j],f[i][j]);
            pr=r;
        }
        for(int j=pr;j<ys-1;++j)un(f[i-1][j],f[i][j]);
    }
    for(int i=1;i<ys-1;++i){
        int pr=0;
        for(pii p:ony[i]){
            int l=p.f,r=p.s;
            for(int j=pr;j<l;++j)un(f[j][i-1],f[j][i]);
            pr=r;
        }
        for(int j=pr;j<xs-1;++j)un(f[j][i-1],f[j][i]);
    }
    if(0<=ax[0]||0>=ax[xs-1]||0<=ay[0]||0>=ay[ys-1]){
        cout<<"INF\n";
        return 0;
    }
    int xpos=upper_bound(ax,ax+xs,0)-ax-1;
    int ypos=upper_bound(ay,ay+ys,0)-ay-1;
    int pos=get(f[xpos][ypos]);
    if(inf[pos])cout<<"INF\n";
    else cout<<ar[pos]<<'\n';
    return 0;
}

Measured memory_bytes: 294540