#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
typedef pair<Int,Int> P;

const Int INF = 1000000001;

int main(){
    Int N, M;
    cin >> N >> M;
    vector<Int> A(N), B(N), C(N);
    vector<Int> D(M), E(M), F(M);

    rep(i,N) cin >> A[i] >> B[i] >> C[i];
    rep(j,M) cin >> D[j] >> E[j] >> F[j];

    set<Int> xs, ys;

    xs.insert(0);
    ys.insert(0);
    rep(i,N) {
        xs.insert(C[i]);
        ys.insert(A[i]);
        ys.insert(B[i]);
    }
    rep(j,M) {
        xs.insert(E[j]);
        xs.insert(F[j]);
        ys.insert(D[j]);
    }

    Int num_of_xs1 = 0, num_of_ys1 = 0, num_of_xs, num_of_ys;
    for (auto ite = xs.begin(); ite != xs.end(); ++ite) num_of_xs1++;
    for (auto ite = ys.begin(); ite != ys.end(); ++ite) num_of_ys1++;
    num_of_xs = num_of_xs1 * 2 + 3;
    num_of_ys = num_of_ys1 * 2 + 3;


    vector<Int> ess_xs, ess_ys;

    for (auto ite = xs.begin(); ite != xs.end(); ++ite) ess_xs.push_back(*ite);
    for (auto ite = ys.begin(); ite != ys.end(); ++ite) ess_ys.push_back(*ite);

    sort(ess_xs.begin(),ess_xs.end());
    sort(ess_ys.begin(),ess_ys.end());




    vector<Int> widths(num_of_xs, 0), heights(num_of_ys, 0);

    widths[1] = ess_xs[0] + INF;
    widths[num_of_xs - 2] = INF - ess_xs[num_of_xs1-1];
    rep(i,num_of_xs1-1) {
        widths[2 * i + 3] = ess_xs[i+1] - ess_xs[i];
    }

    heights[1] = ess_ys[0] + INF;
    heights[num_of_ys - 2] = INF - ess_ys[num_of_ys1-1];
    rep(i,num_of_ys1-1) {
        heights[2 * i + 3] = ess_ys[i+1] - ess_ys[i];
    }


    map<Int, Int> f_x, f_y;

    rep(i,num_of_xs1) {
        int x = i * 2 + 2;
        int y = ess_xs[i];

        f_x[y] = x;
    }

    rep(i,num_of_ys1) {
        int x = i * 2 + 2;
        int y = ess_ys[i];

        f_y[y] = x;
    }
    

    Int start_x, start_y;
    

    start_x = f_x[0];
    start_y = f_y[0];





    vector<vector<bool>> NG(num_of_xs, vector<bool>(num_of_ys, false));
    vector<vector<bool>> visited(num_of_xs, vector<bool>(num_of_ys, false));

    rep(i,N) {
        Int xc = f_x[C[i]], ya = f_y[A[i]], yb = f_y[B[i]];
        for(Int k = ya; k <= yb; k++) {
            NG[xc][k] = true;
        }
    }

    rep(i,M) {
        Int yd = f_y[D[i]], xe = f_x[E[i]], xf = f_x[F[i]];
        for(Int k = xe; k <= xf; k++) {
            NG[k][yd] = true;
        }
    }


    

    queue<P> que;
    que.push(make_pair(start_x, start_y));
    visited[start_x][start_y] = true;


    Int ans = 0;


    while(!que.empty()) {
        P now = que.front();
        rep(i, 3) {
            rep(j, 3) {
                if (i != 1 || j != 1) {
                    Int xnow, ynow;
                    xnow = now.first - 1 + i;
                    ynow = now.second - 1 + j;

                    if (xnow == 0 || xnow == num_of_xs - 1 || ynow == 0 || ynow == num_of_ys - 1) {
                        cout << "INF" << endl;
                        return 0;
                    }

                    if ((!visited[xnow][ynow]) && (!NG[xnow][ynow])) {
                        if (xnow % 2 == 1 && ynow % 2 == 1) ans += widths[xnow] * heights[ynow];
                        visited[xnow][ynow] = true;
                        que.push(make_pair(xnow,ynow));
                    }
                }
            }
        }
        que.pop();
    }

    cout << ans << endl;
}

Measured memory_bytes: 13568