/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
bool check[3200][3200] = {};
bool line_yoko[3010][3010] = {};
bool line_tate[3010][3010] = {};

void solve(){
    ll N,M;
    cin >> N >> M;
    ll A[1010], B[1010], C[1010];
    ll D[1010], E[1010], F[1010];

    // 座標圧縮
    vector<ll> x, y;
    x.push_back(-INF); x.push_back(INF);
    y.push_back(-INF); y.push_back(INF);
    x.push_back(0); y.push_back(0);
    rep(i,0,N){
        cin >> A[i] >> B[i] >> C[i];
        y.push_back(C[i]);
        x.push_back(A[i]); x.push_back(B[i]);
    }
    rep(i,0,M){
        cin >> D[i] >> E[i] >> F[i];
        x.push_back(D[i]);
        y.push_back(E[i]); y.push_back(F[i]);
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    x.erase(unique(x.begin(), x.end()), x.end());
    y.erase(unique(y.begin(), y.end()), y.end());
    vector<ll> diff_x, diff_y;
    ll sz_x = x.size();
    rep(i,0,sz_x-1){
        diff_x.push_back(x[i+1] - x[i]);
    }
    ll sz_y = y.size();
    rep(i,0,sz_y-1){
        diff_y.push_back(y[i+1] - y[i]);
    }
    rep(i,0,N){
        A[i] = lower_bound(x.begin(), x.end(), A[i]) - x.begin();
        B[i] = lower_bound(x.begin(), x.end(), B[i]) - x.begin();
        C[i] = lower_bound(y.begin(), y.end(), C[i]) - y.begin();
    }
    rep(i,0,M){
        D[i] = lower_bound(x.begin(), x.end(), D[i]) - x.begin();
        E[i] = lower_bound(y.begin(), y.end(), E[i]) - y.begin();
        F[i] = lower_bound(y.begin(), y.end(), F[i]) - y.begin();
    }

    // printa(diff_x, sz_x-1);
    // printa(diff_y, sz_y-1);


    rep(i,0,N){
        rep(j,A[i],B[i]){
            line_tate[j][C[i]] = true;
        }
    }
 
    rep(i,0,M){
        rep(j,E[i],F[i]){
            line_yoko[D[i]][j] = true;
        }
    }

    queue<lpair> que;
    ll x0 = lower_bound(x.begin(), x.end(), 0) - x.begin();
    ll y0 = lower_bound(y.begin(), y.end(), 0) - y.begin();
    que.push({x0,y0});
    bool ok = true;

    while(not que.empty()){
        lpair l1 = que.front();
        que.pop();
        ll x = l1.first, y = l1.second;
        if(x > 3100 || y > 3100){
            ok = false;
            break;
        }

        if(x < 0 || y < 0) continue;
        if(check[x][y]) continue;
        check[x][y] = true;
        if(not line_yoko[x+1][y]){
            if(not check[x+1][y]) que.push({x+1, y});
        }
        if(not line_yoko[x][y]){
            if(not check[x-1][y]) que.push({x-1, y});
        }
        if(not line_tate[x][y+1]){
            if(not check[x][y+1]) que.push({x, y+1});
        }
        if(not line_tate[x][y]){
            if(not check[x][y-1]) que.push({x, y-1});
        }
    }
    if(not ok){
        print("INF");
        return;
    }
    ll ans = 0;
    rep(i,0,3010){
        rep(j,0,3010){
            if(check[i][j]){
                ans += diff_x[i] * diff_y[j];
            }
        }
    }
    print(ans);
    // rep(i,0,10){
    //     rep(j,0,10){
    //         cout << check[i][j];
    //     }
    //     cout << endl;
    // }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}

Measured memory_bytes: 27496