#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]-1);
        xs.emplace_back(B[i]);

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

        xs.emplace_back(D[i]-1);
        xs.emplace_back(D[i]);

        ys.emplace_back(E[i]);
        ys.emplace_back(F[i]-1);
        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();
    }
    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();
    }

    int Xsz = xs.size();
    int Ysz = ys.size();

    using state = tuple<int,int,int,int>;
    set<state> cannot_move;
    for(int i = 0; i < N;i++){
        for(int j = A[i]; j < B[i]; j++){
            cannot_move.emplace(j,C[i]-1,j,C[i]);
            cannot_move.emplace(j,C[i],j,C[i]-1);
        }
    }
    for(int i = 0; i < M;i++){
        for(int j = E[i]; j < F[i]; j++){
            cannot_move.emplace(D[i]-1,j,D[i],j);
            cannot_move.emplace(D[i],j,D[i]-1,j);
        }
    }

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

    vector<vector<ll>> ok(Xsz,vector<ll>(Ysz,INF));

    using Item = tuple<int,int,int>;
    priority_queue<Item,vector<Item>,greater<Item>> pq;
    pq.emplace(0,x_zero,y_zero);
    ok[x_zero][y_zero] = 0;
    // queue<pii> q; q.emplace(x_zero,y_zero);
    int dx[4] = {1,0,-1,0};
    int dy[4] = {0,1,0,-1};

    while(pq.size()){
        int dist;
        int x,y; tie(dist,x,y) = pq.top(); pq.pop();

        if(ok[x][y] < dist) continue;

        if(x == 0 || y == 0 || x == Xsz-1 || y == Ysz-1){
            res = -1;
            break;
        }
        
        for(int k = 0; k < 4;k++){
            int nx = x + dx[k];
            int ny = y + dy[k];

            if(nx < 0 || nx >= Xsz || ny < 0 || ny >= Ysz) continue;
            if(cannot_move.count(state(x,y,nx,ny))) continue;
            if(ok[nx][ny] > ok[x][y] + 1){
                ok[nx][ny] = ok[x][y] + 1;
                pq.emplace(ok[nx][ny],nx,ny);
            }
        }
    }
    // cout << ok << endl;

    if(res == -1){
        cout << "INF" << endl;
    }else{
        for(int i = 0; i < Xsz-1; i++){
            for(int j = 0; j < Ysz-1;j++){
                if(ok[i][j]!=INF){
                    res += (xs[i+1]-xs[i])*(ys[i+1]-ys[i]);
                }
            }
        }
        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;
}