#include<bits/stdc++.h>

using namespace std;
using ll = long long int;

int main(void) {
    constexpr ll MOD = 1e9 + 7;
    constexpr double PI = acos(-1);
    cout << fixed << setprecision(16);
    cin.tie(0); ios::sync_with_stdio(false);

    ll n, m;
    cin >> n >> m;

    vector<tuple<ll,ll,ll>> def(m), cab(n);
    for(auto &[c, a, b]: cab) cin >> a >> b >> c;
    for(auto &[a, b, c]: def) cin >> a >> b >> c;

    sort(cab.begin(), cab.end());
    sort(def.begin(), def.end());

    vector<ll> xs(5*(n+m), 1e10), ys(5*(n+m), 1e10);
    {
        ll xi = 0, yi = 0;
        xs[xi++] = -1e10;
        ys[yi++] = -1e10;
        xs[xi++] =  1e10;
        ys[yi++] =  1e10;

        for(auto &[c, a, b]: cab) {
            xs[xi++] = a;
            xs[xi++] = b;
            ys[yi++] = c;
        }
        for(auto &[d, e, f]: def) {
            xs[xi++] = d;
            ys[yi++] = e;
            ys[yi++] = f;
        }

        sort(xs.begin(), xs.end());
        sort(ys.begin(), ys.end());
        xs.erase(unique(xs.begin(), xs.end()), xs.end());
        ys.erase(unique(ys.begin(), ys.end()), ys.end());
    }

    auto sur = [&](ll x, ll y) -> ll {
        if(xs[x+1] == 1e10 || ys[y+1] == 1e10 || xs[x] == -1e10 || ys[y] == -1e10)
            return 3e18;
        return (xs[x+1] - xs[x]) * (ys[y+1] - ys[y]);
    };

    {
        vector<tuple<ll,ll,ll>> ncab;
        for(ll i=0; i<n; ) {
            vector<pair<ll,ll>> v;
            ll cc = get<0>(cab[i]);

            while(i<n) {
                auto [c, a, b] = cab[i];
                if(c != cc) break;
                v.push_back({a, 0});
                v.push_back({b, 1});
                i++;
            }
            sort(v.begin(), v.end());

            ll s = 0, p = -1e9;
            for(auto [x, t]: v) {
                if(t == 0) {
                    if(s++ == 0) p = x;
                } else {
                    if(--s == 0) ncab.push_back({cc, p, x});
                }
            }
        }
        cab = move(ncab);
    }
    {
        vector<tuple<ll,ll,ll>> ndef;
        for(ll i=0; i<m; ) {
            vector<pair<ll,ll>> v;
            ll cc = get<0>(def[i]);

            while(i<m) {
                auto [c, a, b] = def[i];
                if(c != cc) break;
                v.push_back({a, 0});
                v.push_back({b, 1});
                i++;
            }
            sort(v.begin(), v.end());

            ll s = 0, p = -1e9;
            for(auto [x, t]: v) {
                if(t == 0) {
                    if(s++ == 0) p = x;
                } else {
                    if(--s == 0) ndef.push_back({cc, p, x});
                }
            }
        }
        def = move(ndef);
    }

    ll si = upper_bound(xs.begin(), xs.end(), 0ll) - xs.begin();
    ll sj = upper_bound(ys.begin(), ys.end(), 0ll) - ys.begin();
    si--, sj--;

    ll res = 0;
    queue<pair<ll,ll>> q;
    vector<vector<int>> vis(xs.size(), vector<int>(ys.size()));
    {
        q.push({si, sj});
        vis[si][sj] = 1;

        while(!q.empty()) {
            auto [i, j] = q.front(); q.pop();
            // cout << '!' << xs[i] << ' ' << ys[j] << endl;

            res += sur(i, j);
            if(sur(i, j) == 3e18) {
                cout << "INF" << endl;
                exit(0);
            }

            if(!vis[i-1][j]){
                bool ng = false;
                auto it = upper_bound(def.begin(), def.end(), make_tuple(xs[i], ys[j], 1e10));
                if(it!=def.begin()) it--;
                auto [d, e, f] = *it;
                ng = d == xs[i] && e <= ys[j] && ys[j+1] <= f;
                if(!ng) q.push({i-1,j}), vis[i-1][j] = 1;
            }
            if(!vis[i+1][j]){
                bool ng = false;
                auto it = upper_bound(def.begin(), def.end(), make_tuple(xs[i+1], ys[j], 1e10));
                if(it!=def.begin()) it--;
                auto [d, e, f] = *it;
                ng = d == xs[i+1] && e <= ys[j] && ys[j+1] <= f;
                if(!ng) q.push({i+1,j}), vis[i+1][j] = 1;
            }
            if(!vis[i][j-1]){
                bool ng = false;
                auto it = upper_bound(cab.begin(), cab.end(), make_tuple(ys[j], xs[i], 1e10));
                if(it!=cab.begin()) it--;
                auto [c, a, b] = *it;
                ng = c == ys[j] && a <= xs[i] && xs[i+1] <= b;
                if(!ng) q.push({i,j-1}), vis[i][j-1] = 1;
            }
            if(!vis[i][j+1]){
                bool ng = false;
                auto it = upper_bound(cab.begin(), cab.end(), make_tuple(ys[j+1], xs[i], 1e10));
                if(it!=cab.begin()) it--;
                auto [c, a, b] = *it;
                ng = c == ys[j+1] && a <= xs[i] && xs[i+1] <= b;
                if(!ng) q.push({i,j+1}), vis[i][j+1] = 1;
            }
        };
    }
    cout << res << endl;

}


Measured memory_bytes: 39156