#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll,ll>;

ll solve() {
    ll N, M;
    cin >> N >> M;
    vector<ll> xs, ys;
    vector<ll> A(N), B(N), C(N);
    ll INF = 1LL<<60;
    ll xm = INF, ym = INF;
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i] >> B[i] >> C[i];
        A[i] *= 2;
        B[i] *= 2;
        C[i] *= 2;
        xm = min(xm, A[i]);
        xm = min(xm, B[i]);
        ym = min(ym, C[i]);
        xs.push_back(A[i]);
        xs.push_back(A[i]+1);
        xs.push_back(B[i]);
        xs.push_back(B[i]+1);
        ys.push_back(C[i]);
        ys.push_back(C[i]+1);
    }
    vector<ll> D(M), E(M), F(M);
    for ( int i = 0; i < M; i++ ) {
        cin >> D[i] >> E[i] >> F[i];
        D[i] *= 2;
        E[i] *= 2;
        F[i] *= 2;
        xm = min(xm, D[i]);
        ym = min(xm, E[i]);
        ym = min(ym, F[i]);
        xs.push_back(D[i]);
        xs.push_back(D[i]+1);
        ys.push_back(E[i]);
        ys.push_back(E[i]+1);
        ys.push_back(F[i]);
        ys.push_back(F[i]+1);
    }
    xs.push_back(xm);
    ys.push_back(ym);
    xs.push_back(0);
    ys.push_back(0);

    auto compress = [](vector<ll>& v) {
        vector<ll> vs(v);
        sort(vs.begin(), vs.end());
        vs.erase(unique(vs.begin(), vs.end()), vs.end());
        vector<ll> ord(v.size());
        for ( int i = 0; i < v.size(); i++ ) {
            ord[i] = lower_bound(vs.begin(), vs.end(), v[i]) - vs.begin();
        }
        return make_tuple(ord,vs); // order, value[order]
    };
    // vector<ll> ord_$1, v_$1;
    // tie(ord_$1, v_$1) = compress($1);

    vector<ll> ord_x, v_x;
    tie(ord_x, v_x) = compress(xs);
    vector<ll> ord_y, v_y;
    tie(ord_y, v_y) = compress(ys);
    for ( int i = 0; i < N; i++ ) {
        A[i] = lower_bound(v_x.begin(), v_x.end(), A[i]) - v_x.begin();
        B[i] = lower_bound(v_x.begin(), v_x.end(), B[i]) - v_x.begin();
        C[i] = lower_bound(v_y.begin(), v_y.end(), C[i]) - v_y.begin();
    }
    for ( int i = 0; i < M; i++ ) {
        D[i] = lower_bound(v_x.begin(), v_x.end(), D[i]) - v_x.begin();
        E[i] = lower_bound(v_y.begin(), v_y.end(), E[i]) - v_y.begin();
        F[i] = lower_bound(v_y.begin(), v_y.end(), F[i]) - v_y.begin();
    }
    ll x0 = lower_bound(v_x.begin(), v_x.end(), 0LL) - v_x.begin();
    ll y0 = lower_bound(v_y.begin(), v_y.end(), 0LL) - v_y.begin();


    vector<vector<int>> a(v_x.size(), vector<int>(v_y.size()));
    for ( int i = 0; i < N; i++ ) {
        for ( ll j = A[i]; j <= B[i]; j++ ) {
            a[j][C[i]] = -1;
        }
    }
    for ( int i = 0; i < M; i++ ) {
        for ( ll j = E[i]; j <= F[i]; j++ ) {
            a[D[i]][j] = -1;
        }
    }

    vector<int> dh = {0, 1, 0, -1}, dw = {1, 0, -1, 0};
    queue<pii> q;
    a[x0][y0] = 1;
    q.push(pii(x0,y0));
    while ( !q.empty() ) {
        int x1 = q.front().first, y1 = q.front().second;
        q.pop();
        for ( int ii = 0; ii < 4; ii++ ) {
            int x = x1 + dh[ii];
            int y = y1 + dw[ii];
            if ( x < 0 || x >= v_x.size() || y < 0 || y >= v_y.size() ) continue;
            if ( a[x][y] != 0 ) continue;
            a[x][y] = 1;
            q.push(pii(x,y));
        }
    }

    for ( int i = 0; i < v_x.size(); i++ ) {
        if ( a[i][0] == 1 || a[i][v_y.size()-1] == 1 ) return -1;
    }
    for ( int i = 0; i < v_y.size(); i++ ) {
        if ( a[0][i] == 1 || a[v_x.size()-1][0] == 1 ) return -1;
    }

    ll ans = 0;
    for ( int x = 0; x < v_x.size()-1; x++ ) {
        for ( int y = 0; y < v_y.size()-1; y++ ) {
            if ( a[x][y] == 1 ) {
                ll wx = (v_x[x+1]+2*abs(v_x[x]))/2 - (v_x[x]+2*abs(v_x[x]))/2;
                ll wy = (v_y[y+1]+2*abs(v_y[y]))/2 - (v_y[y]+2*abs(v_y[y]))/2;
                ans += wx * wy;
            }
        }
    }
    return ans;
}

int main() {
    ll ans = solve();
    if ( ans < 0 ) cout << "INF" << "\n";
    else cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 144464