#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    int N,M; cin >> N >> M;
    vector<ll> xs,ys;
    vector<ll> A(N),B(N),C(N),D(M),E(M),F(M);

    xs.emplace_back(0); ys.emplace_back(0);
    for(int i = 0; i < N;i++){
        cin >> A[i] >> B[i] >> C[i];

        xs.emplace_back(A[i]);
        xs.emplace_back(B[i]);

        ys.emplace_back(C[i]);
    }
    for(int i = 0; i < M;i++){
        cin >> D[i] >> E[i] >> F[i];

        xs.emplace_back(D[i]);

        ys.emplace_back(E[i]);
        ys.emplace_back(F[i]);
    }

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

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


    for(int i = 0; i < N;i++){
        A[i] = lower_bound(xs.begin(),xs.end(),A[i]) - xs.begin();
        B[i] = lower_bound(xs.begin(),xs.end(),B[i]) - xs.begin();

        C[i] = lower_bound(ys.begin(),ys.end(),C[i]) - ys.begin();

        // 線分（奇数番号）に変換
        A[i] = 2*A[i]+1;
        B[i] = 2*B[i]+1;
        C[i] = 2*C[i]+1;
    }
    for(int i = 0; i < M;i++){
        D[i] = lower_bound(xs.begin(),xs.end(),D[i]) - xs.begin();

        E[i] = lower_bound(ys.begin(),ys.end(),E[i]) - ys.begin();
        F[i] = lower_bound(ys.begin(),ys.end(),F[i]) - ys.begin();

        // 線分（奇数番号）に変換
        D[i] = 2*D[i]+1;
        E[i] = 2*E[i]+1;
        F[i] = 2*F[i]+1;
    }


    int xsz = (int)xs.size()*2 + 1;
    int ysz = (int)ys.size()*2 + 1;

    vector<vector<int>> state(xsz,vector<int>(ysz,0));

    int x_zero = 2*(lower_bound(xs.begin(),xs.end(),0) - xs.begin());
    int y_zero = 2*(lower_bound(ys.begin(),ys.end(),0) - ys.begin());

    for(int i = 0; i < N;i++){
        for(int j = A[i]; j <= B[i]; j++){
            state[j][C[i]] = 1;
        }
    }

    for(int i = 0; i < M;i++){
        for(int j = E[i]; j <= F[i]; j++){
            state[D[i]][j] = 1;
        }
    }
    // cout << state << endl;

    int dir[4] = {1,0,-1,0};
    queue<pii> q; q.emplace(x_zero,y_zero);
    vector<vector<int>> can_visit(xsz,vector<int>(ysz,0));
    can_visit[x_zero][y_zero] = 1;

    // cout << can_visit << endl;
    while(q.size()){
        int x,y; tie(x,y) = q.front(); q.pop();

        if(x == 0 || x == xsz-1 || y == 0 || y == ysz-1){
            res = -1;
            break;
        }
        for(int k = 0; k < 4;k++){
            int nx = x + dir[k];
            int ny = y + dir[k^1];

            if(nx < 0 || nx >= xsz || ny < 0 || ny >= ysz) continue;
            if(state[nx][ny]) continue;
            if(can_visit[nx][ny]) continue;

            can_visit[nx][ny] = true;
            q.emplace(nx,ny);
        }
    }
    if(res == -1){
        cout << "INF" << endl;
    }else{
        for(int i = 0; i < xsz; i+=2){
            for(int j = 0; j < ysz; j+=2){
                if(can_visit[i][j]){
                    // cout << i << " " << j << endl;
                    // can_visit[i][j] = 2;
                    res += (xs[i/2]-xs[i/2-1])*(ys[j/2]-ys[j/2-1]);
                }
            }
        }
        cout << res << endl;
    }
    return res;
}
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    solve<ll>(0);
    // cout << fixed << setprecision(12) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 285424