#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rrep(i, n) for(ll i = n - 1; i > -1; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
const ll INF = 999999999999999;
const ll MOD = 1000000007 /*988244353*/;
const ll MAX_N = 1010010;
ll a, b, c, d, e, f, h, x, y, z, p, q, m, n, t, r, k, w, l, ans, i, j;
string S, T;
vl A, B;
map<ll, ll> M1, M2;
vector<pair<ll, PP>> VP1, VP2;
set<ll> S1, S2;
vl g[MAX_N];
vl visited(MAX_N, 0);
void dfs(ll x) {
    visited[x] = 1;
    for(ll i : g[x]) {
        if(visited[i] == 0) {
            dfs(i);
        }
    }
}
void solve() {
    sort(all(VP1));
    sort(all(VP2));
    sort(all(A));
    sort(all(B));
    x = A.size() - 1;
    y = B.size() - 1;
    rep(i, x - 1) {
        rep(j, y) {
            g[i * y + j].pb((i + 1) * y + j);
            g[(i + 1) * y + j].pb(i * y + j);
        }
    }

    rep(i, y - 1) {
        rep(j, x) {
            g[j * y + i].pb(j * y + i + 1);
            g[j * y + i + 1].pb(j * y + i);
        }
    }

    rep(t, e) {
        a = VP1[t].se.fi;
        b = VP1[t].se.se;
        p = lower_bound(all(B), a) - B.begin();
        q = upper_bound(all(B), b) - B.begin() - 1;
        i = lower_bound(all(A), VP1[t].fi) - A.begin() - 1;
        for(j = p; j < q; j++) {
            for(auto &h : g[i * y + j]) {
                if(h == (i + 1) * y + j)
                    h = i * y + j;
            }
            for(auto &h : g[(i + 1) * y + j]) {
                if(h == i * y + j)
                    h = (i + 1) * y + j;
            }
        }
    }

    rep(t, f) {
        a = VP2[t].se.fi;
        b = VP2[t].se.se;
        p = lower_bound(all(A), a) - A.begin();
        q = upper_bound(all(A), b) - A.begin() - 1;
        i = lower_bound(all(B), VP2[t].fi) - B.begin() - 1;
        for(j = p; j < q; j++) {
            for(auto &h : g[j * y + i]) {
                if(h == j * y + i + 1)
                    h = j * y + i;
            }
            for(auto &h : g[j * y + i + 1]) {
                if(h == j * y + i)
                    h = j * y + i + 1;
            }
        }
    }

    a = lower_bound(all(A), 0) - A.begin() - 1;
    b = lower_bound(all(B), 0) - B.begin() - 1;

    dfs(a * y + b);

    if(visited[0]) {
        cout << "INF" << endl;
        return;
    }

    /*rep(i, x) {
        rep(j, y) { cout << visited[i * y + j]; }
        cout << endl;
    }*/

    rep(i, x) {
        rep(j, y) {
            if(visited[i * y + j])
                ans += (A[i + 1] - A[i]) * (B[j + 1] - B[j]);
        }
    }

    cout << ans << endl;
}
int main() {
    // cout<<fixed<<setprecision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> e >> f;
    S1.insert(-2000000000);
    S2.insert(-2000000000);
    S1.insert(2000000000);
    S2.insert(2000000000);
    rep(i, e) {
        cin >> a >> b >> c;
        VP1.push_back({c, {a, b}});
        S1.insert(c);
    }
    rep(i, f) {
        cin >> a >> b >> c;
        VP2.push_back({a, {b, c}});
        S2.insert(a);
    }
    for(auto ite = S1.begin(); ite != S1.end(); ite++) {
        A.push_back(*ite);
    }
    for(auto ite = S2.begin(); ite != S2.end(); ite++) {
        B.push_back(*ite);
    }
    solve();
}


Measured memory_bytes: 116740