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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

class unionfind {
    vector<int> par, rank;

   public:
    void init(int n) {
        par.resize(n);
        rank.resize(n);

        for (int i = 0; i < n; i++) {
            par[i] = i;
            rank[i] = 0;
        }
    }

    int find(int x) {
        if (par[x] == x)
            return x;
        else
            return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;

        if (rank[x] < rank[y])
            par[x] = y;
        else {
            par[y] = x;
            if (rank[x] == rank[y]) ++rank[x];
        }
    }

    bool same(int x, int y) { return (find(x) == find(y)); }
};

const int INF = TEN(9) + 10;

int main() {
    int N, M;
    cin >> N >> M;
    V<pair<int, pii>> vv(N), vh(M);
    V<int> xs{-INF, 0, INF}, ys{-INF, 0, INF};
    rep(i, N) {
        int A, B, C;
        cin >> A >> B >> C;
        vv[i] = mp(C, mp(A, B));
        xs.pb(A);
        xs.pb(B);
        ys.pb(C);
    }
    rep(i, M) {
        int D, E, F;
        cin >> D >> E >> F;
        vh[i] = mp(D, mp(E, F));
        ys.pb(E);
        ys.pb(F);
        xs.pb(D);
    }

    sort(ALL(xs));
    sort(ALL(ys));
    xs.erase(unique(ALL(xs)), xs.end());
    ys.erase(unique(ALL(ys)), ys.end());

    sort(ALL(vv));
    sort(ALL(vh));

    auto get_id = [&](int i, int j) { return i * ys.size() + j; };
    auto get_p = [&](const V<int>& vs, int x) {
        return lower_bound(ALL(vs), x) - vs.begin();
    };

    unionfind uf;
    uf.init(xs.size() * ys.size());

    rep(i, N) {
        int A, B, C;
        C = vv[i].fi;
        tie(A, B) = vv[i].se;
        A = get_p(xs, A);
        B = get_p(xs, B);
        C = get_p(ys, C);
        vv[i] = mp(C, mp(A, B));
    }
    rep(i, M) {
        int A, B, C;
        A = vh[i].fi;
        tie(B, C) = vh[i].se;
        A = get_p(xs, A);
        B = get_p(ys, B);
        C = get_p(ys, C);
        vh[i] = mp(A, mp(B, C));
    }

    rep(i, xs.size() - 1) {
        V<int> acm(ys.size() + 1);
        rep(j, M) {
            if (vh[j].fi == i + 1) {
                int l, r;
                tie(l, r) = vh[j].se;
                acm[l]++;
                acm[r]--;
            }
        }
        rep(i, ys.size()) { acm[i + 1] += acm[i]; }
        rep(j, ys.size() - 1) {
            if (acm[j] == 0) {
                uf.unite(get_id(i, j), get_id(i + 1, j));
            }
        }
    }

    rep(j, ys.size() - 1) {
        V<int> acm(xs.size() + 1);
        rep(i, N) {
            if (vv[i].fi == j + 1) {
                int l, r;
                tie(l, r) = vv[i].se;
                acm[l]++;
                acm[r]--;
            }
        }
        rep(i, xs.size()) { acm[i + 1] += acm[i]; }
        rep(i, xs.size() - 1) {
            if (acm[i] == 0) {
                uf.unite(get_id(i, j), get_id(i, j + 1));
            }
        }
    }

    V<ll> sz(xs.size() * ys.size());
    rep(i, xs.size() - 1) {
        rep(j, ys.size() - 1) {
            debug(i, j, uf.find(get_id(i, j)));
            sz[uf.find(get_id(i, j))] +=
                ll(xs[i + 1] - xs[i]) * (ys[j + 1] - ys[j]);
        }
    }

    int x = get_p(xs, 0);
    int y = get_p(ys, 0);
    int v = uf.find(get_id(x, y));

    if (uf.same(get_id(0, 0), v)) {
        puts("INF");
    } else {
        cout << sz[v] << endl;
    }

    return 0;
}

Measured memory_bytes: 144176