#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (200000000009LL)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

struct se{
    ll l,r,c;
};

int main() {


    int N,M;
    Scd2(N,M);

    int x,y,z;
    vector<se> v(N);
    vector<se> h(M);
    Rep(i,N){
        Scd3(x,y,z);
        v[i] = {x,y,z};
    }
    v.push_back({-INF,INF,-INF});
    v.push_back({-INF,INF,INF });
    Rep(i,M){
        Scd3(x,y,z);
        h[i] = {y,z,x};
    }
    h.push_back({-INF,INF,-INF});
    h.push_back({-INF,INF,INF });

    map<ll,int> zx;
    map<ll,int> zy;

    Rep(i,N+2){
        zx[v[i].c] = 0;
        zy[v[i].l] = 0;
        zy[v[i].r] = 0;
    }
    Rep(i,M+2){
        zy[h[i].c] = 0;
        zx[h[i].l] = 0;
        zx[h[i].r] = 0;
    }

    int cnt = 0;
    for( auto &t : zx ){
        t.second = cnt++;
    }
    int W = cnt-1;
    cnt = 0;
    for( auto &t : zy ){
        t.second = cnt++;
    }
    int H = cnt-1;

    vector<vi> eh1(H,vi(W,1));
    vector<vi> eh2(H,vi(W,1));
    vector<vi> ev1(H,vi(W,1));
    vector<vi> ev2(H,vi(W,1));

    Rep(i,N){
        int x = zx[v[i].c];
        auto rzy = zy.find(v[i].r); rzy++;
        for( auto lzy = ++(zy.find(v[i].l)); lzy != rzy; lzy++ ){
            int y = lzy->second;
            eh1[y-1][x-1] = 0;
            eh2[y-1][x] = 0;
        }
    }
    Rep(i,M){
        int y = zy[h[i].c];
        auto rzx = zx.find(h[i].r); rzx++;
        for( auto lzx = ++(zx.find(h[i].l)); lzx != rzx; lzx++ ){
            int x = lzx->second;
            ev1[y-1][x-1] = 0;
            ev2[y][x-1]   = 0;
        }
    }


    vector<vl> area(H,vl(W));
    auto zzy1 = zy.begin();
    auto zzx1 = zx.begin();
    auto zzy2 = zy.begin();
    auto zzx2 = zx.begin();
    zzy2++;
    zzx2++;
    Rep(hi,H){
        zzx1 = zx.begin();
        zzx2 = zx.begin();
        zzx2++;
        ll hei = zzy2->first - zzy1->first;
        Rep(wi,W){
            ll wid = zzx2->first - zzx1->first;
            area[hi][wi] = hei * wid;
            if( hi == 0 || hi == H-1 || wi == 0 || wi == W-1 ){
                area[hi][wi] = -1;
            }
            zzx1++;
            zzx2++;
        }
        zzy1++;
        zzy2++;
    }

    vector<vi> ans(H,vi(W,0));
    stack<pii> st;
    vi initx;
    vi inity;

    auto zxzero = zx.find(0);
    if( zxzero == zx.end() ){
        initx.push_back((--zx.lower_bound(0))->second);
    }else{
        initx.push_back(zxzero->second);
        initx.push_back((--zxzero)->second);
    }
    auto zyzero = zy.find(0);
    if( zyzero == zy.end() ){
        inity.push_back((--zy.lower_bound(0))->second);
    }else{
        inity.push_back(zyzero->second);
        inity.push_back((--zyzero)->second);
    }

    for( int yy : inity ) for( int xx : initx ){
        st.push({yy,xx});
        ans[yy][xx] = 2;
    }


    while( st.size() ){
        int fy = st.top().first;
        int fx = st.top().second;
        st.pop();
        if( eh1[fy][fx] && fx != W-1 && ans[fy][fx+1] == 0 ) st.push({fy,fx+1}), ans[fy][fx+1] = 1;
        if( eh2[fy][fx] && fx != 0   && ans[fy][fx-1] == 0 ) st.push({fy,fx-1}), ans[fy][fx-1] = 1;
        if( ev1[fy][fx] && fy != H-1 && ans[fy+1][fx] == 0 ) st.push({fy+1,fx}), ans[fy+1][fx] = 1;
        if( ev2[fy][fx] && fy != 0   && ans[fy-1][fx] == 0 ) st.push({fy-1,fx}), ans[fy-1][fx] = 1;

    }

    bool inf = false;
    ll arans = 0;

    Rep(hi,H) { Rep(wi,W) {
        // printf ("%d", ans[hi][wi] );
        if( ans[hi][wi] ) {
            arans += area[hi][wi];
            if( area[hi][wi] == -1 ) inf = true;
        }
        }
        // printf ("\n");
    }

    if( inf ) printf ("INF\n");
    else printf ("%lld\n", arans );

    return 0;
}



Measured memory_bytes: 280908