#include<bits/stdc++.h>
using namespace std;


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


PI field[6060][6060];
bool ok[6060][6060];
bool visited[6060][6060];

li len_x[6060];
li len_y[6060];

set<li> x;
set<li> y;

map<li, li> za_x;
map<li, li> za_y;

pair<li, PI> tatesen[1010];
pair<li, PI> yokosen[1010];
li n, m;

li dy[] = { -1, 1, 0, 0};
li dx[] = {0, 0, -1, 1};

int main() {
    cin >> n >> m;
    rin{
        cin >> yokosen[i].S.F >> yokosen[i].S.S >> yokosen[i].F;
        x.insert(yokosen[i].S.F);
        x.insert(yokosen[i].S.S);
        y.insert(yokosen[i].F);
    }
    rep(i, m) {
        cin >> tatesen[i].F >> tatesen[i].S.F >> tatesen[i].S.S;
        x.insert(tatesen[i].F);
        y.insert(tatesen[i].S.F);
        y.insert(tatesen[i].S.S);
    }

    // zaatu
    {
        li cnt = 0;
        li prev = -INF;
        for (auto v : x) {
            za_x[v] = cnt * 2 + 1;
            len_x[cnt * 2 + 1] = 0;
            if (prev != -INF) {
                len_x[cnt * 2] = v - prev;
            }
            cnt++;
            prev = v;
        }
        len_x[sz(x) * 2] = -1;
        len_x[0] = -1;
    }
    {
        li cnt = 0;
        li prev = -INF;
        for (auto v : y) {
            za_y[v] = cnt * 2 + 1;
            len_y[cnt * 2 + 1] = 0;
            if (prev != -INF) {
                len_y[cnt * 2] = v - prev;
            }
            cnt++;
            prev = v;
        }
        len_y[sz(y) * 2] = -1;
        len_y[0] = -1;
    }

    /*
        dumpi(x);
        dump(len_x, sz(x) * 2 + 1);
        dumpi(y);
        dump(len_y, sz(y) * 2 + 1);
    */
    {
        // 壁を塗る
        rep(i, 6060) {
            rep(j, 6060) {
                ok[i][j] = true;
            }
        }
        rep(i, n) {
            repp(xx, za_x[yokosen[i].S.F], za_x[yokosen[i].S.S] + 1) {
                ok[za_y[yokosen[i].F]][xx] = false;
            }
        }
        rep(i, m) {
            repp(yy, za_y[tatesen[i].S.F], za_y[tatesen[i].S.S] + 1) {
                ok[yy][za_x[tatesen[i].F]] = false;
            }
        }
    }

    PI s = {0, 0};
    {
        // calc start point index
        li cnt = 0;
        for (auto v : x) {
            if (v >= 0) {
                s.S = cnt * 2;
                break;
            }
            cnt++;
        }
        cnt = 0;
        for (auto v : y) {
            if (v >= 0) {
                s.F = cnt * 2;
                break;
            }
            cnt++;
        }
    }

    queue<PI> q;
    q.push(s);
    li res = 0;
    while (!q.empty()) {
        PI now = q.front();
        q.pop();
        if (visited[now.F][now.S]) {
            continue;
        }
        visited[now.F][now.S] = true;
        if (min(len_y[now.F], len_x[now.S]) < 0) {
            puts("INF");
            return 0;
        }
        res += len_y[now.F] * len_x[now.S];
        rep(i, 4) {
            PI next = {now.F + dy[i], now.S + dx[i]};
            if (!ok[next.F][next.S]) {
                continue;
            }
            q.push(next);
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 75428