#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef tuple<ll, ll, ll> tlll;
typedef pair<int, int> Pii;

const ll INF = 1e9 + 10;

int main() 
{
    int N, M; cin >> N >> M;
    int i, j, ind;
    int rzero, czero;
    int rsize, csize;
    ll now;

    vector<tlll> ver(N);
    for (i = 0; i < N; i++) 
    {
        ll a, b, c; cin >> a >> b >> c;
        ver[i] = tlll(c, a, b);
    }
    sort(ver.begin(), ver.end(), less<tlll>());

    // for (i = 0; i < N; i++)
    // {
    //     ll a, b, c; tie(a, b, c) = ver[i];
    //     cout << a << ' ' << b <<  ' ' << c << endl;
    // }

    vector<ll> zipcol(2*N+1, 0);
    now = get<0>(ver[0]);
    if (0 < now) czero = 0;
    get<0>(ver[0]) = 1;
    zipcol[0] = now + INF;
    ind = 0;
    for (i = 1; i < N; i++)
    {
        if (now != get<0>(ver[i]))
        {
            ind++;
            if (now <= 0 && 0 <= get<0>(ver[i])) czero = ind*2;
            zipcol[ind*2] = get<0>(ver[i]) - now;
            now = get<0>(ver[i]);
        }
        get<0>(ver[i]) = (ind*2) + 1;
    }
    zipcol[(ind+1)*2] = INF - now;
    csize = (ind+1)*2 + 1;
    if (now < 0) czero = csize-1;

    vector<tlll> hor(M);
    for (i = 0; i < M; i++) 
    {
        ll d, e, f; cin >> d >> e >> f;
        hor[i] = tlll(d, e, f);
    }
    sort(hor.begin(), hor.end(), less<tlll>());

    vector<ll> ziprow(2*M+1, 0);
    now = get<0>(hor[0]);
    if (0 < now) rzero = 0;
    get<0>(hor[0]) = 1;
    ziprow[0] = now + INF;
    ind = 0;
    for (i = 1; i < M; i++)
    {
        if (now != get<0>(hor[i]))
        {
            ind++;
            if (now <= 0 && 0 <= get<0>(hor[i])) rzero = ind*2;
            ziprow[ind*2] = get<0>(hor[i]) - now;
            now = get<0>(hor[i]);
        }
        get<0>(hor[i]) = (ind*2) + 1;
    }
    ziprow[(ind+1)*2] = INF - now;
    rsize = (ind+1)*2 + 1;
    if (now < 0) rzero = rsize-1;

    vector<vector<bool>> field(rsize, vector<bool>(csize, false));
    for (j = 0; j < N; j++) 
    {
        ll a, b, c; tie(c, a, b) = ver[j];
        now = -INF;
        for (i = 0; i < rsize; i++)
        {
            if (a <= now && now+ziprow[i] <= b)
            {
                field[i][c] = true;
            }
            now += ziprow[i];
        }
    }

    for (i = 0; i < M; i++)
    {
        ll d, e, f; tie(d, e, f) = hor[i];
        now = -INF;
        for (j = 0; j < csize; j++)
        {
            if (e <= now && now+zipcol[j] <= f)
            {
                field[d][j] = true;
            }
            now += zipcol[j];
        }
    }
    // for (int i = 0; i < rsize; i++) {
    //     for (int j = 0; j < csize; j++) {
    //         if (field[i][j]) cout << '#';
    //         else cout << '.';
    //     }
    //     cout << endl;
    // }
    queue<Pii> q;
    vector<vector<bool>> added(rsize, vector<bool>(csize, false));
    q.push(Pii(rzero, czero)); added[rzero][czero] = true;
    ll ans = 0;
    while (!q.empty())
    {
        int r, c; tie(r, c) = q.front(); 
        q.pop();
        if (r == 0 || r == rsize-1 || c == 0 || c == csize-1) {
            cout << "INF" << endl;
            return 0;
        }
        ans += ziprow[r] * zipcol[c];
        if (!added[r-1][c] && !field[r-1][c]) {q.push(Pii(r-1, c)); added[r-1][c] = true;}
        if (!added[r+1][c] && !field[r+1][c]) {q.push(Pii(r+1, c)); added[r+1][c] = true;}
        if (!added[r][c-1] && !field[r][c-1]) {q.push(Pii(r, c-1)); added[r][c-1] = true;}
        if (!added[r][c+1] && !field[r][c+1]) {q.push(Pii(r, c+1)); added[r][c+1] = true;}
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4940