#include <bits/stdc++.h>

using namespace std;
#define all(x) (x).begin(), (x).end()
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvl;
typedef pair<int,int> pii;
typedef long long ll;
void debugF(ostream &os) {os << endl;}
template <typename Head, typename... Tail>
void debugF(ostream &os, Head H, Tail... T) { os << " " << H; debugF(os, T...); }
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debugF(cout, __VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); os << (i>0 ? " ":"") << v[i++]); return os;}

using t3 = tuple<int,int,int>;
const int inf = 1e9 + 10;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vi xc,yc;
    vector<t3> vl, hl;
    
    int i,j,a,b,c;
    for(i=0;i<n;i++){
        cin >> a >> b >> c;
        vl.push_back({a,b,c});
        xc.push_back(a);
        xc.push_back(b);
        yc.push_back(c);
    }
    for(i=0;i<m;i++){
        cin >> a >> b >> c;
        hl.push_back({a,b,c});
        xc.push_back(a);
        yc.push_back(b);
        yc.push_back(c);
    }
    xc.push_back(-inf);
    xc.push_back(0);
    //xc.push_back(inf);
    yc.push_back(-inf);
    yc.push_back(0);
    //yc.push_back(inf);
    sort(all(xc));
    sort(all(yc));
    xc.resize(unique(all(xc)) - xc.begin());
    yc.resize(unique(all(yc)) - yc.begin());
    int nr = xc.size();
    int nc = yc.size();
    vvb xw(nr, vb(nc));
    vvb yw(nr, vb(nc));

    auto getx = [&](int q) -> int {return lower_bound(all(xc), q) - xc.begin();};
    auto gety = [&](int q) -> int {return lower_bound(all(yc), q) - yc.begin();};

    for(i=0;i<n;i++){
        tie(a,b,c) = vl[i];
        //row row col
        a = getx(a);
        b = getx(b);
        c = gety(c);
        while(a < b){
            xw[a][c] = true;
            a++;
        }
    }
    for(i=0;i<m;i++){
        tie(a,b,c) = hl[i];
        //row col col
        a = getx(a);
        b = gety(b);
        c = gety(c);
        while(b < c){
            yw[a][b] = true;
            b++;
        }
    }
    ll ans = 0;
    vvb clr(nr, vb(nc));
    stack<pii> Q;
    a = getx(0);
    b = gety(0);
    clr[a][b] = true;
    Q.push({a,b});
    vi dx = {0,-1,0,1};
    vi dy = {1,0,-1,0};
    bool isInf = false;
    while(!Q.empty()){
        tie(a,b) = Q.top();
        //debug(a,b);
        Q.pop();
        if(a == 0 || a == nr-1 || b == 0 || b == nc-1){
            isInf = true;
            break;
        }
        ans += (ll(xc[a+1]) - xc[a])*(ll(yc[b+1]) - yc[b]);
        for(i=0;i<4;i++){
            if(i == 0 && xw[a][b+1]) continue;
            if(i == 2 && xw[a][b]) continue;
            if(i == 1 && yw[a][b]) continue;
            if(i == 3 && yw[a+1][b]) continue;
            int newa = a + dx[i];
            int newb = b + dy[i];
            if(clr[newa][newb]) continue;
            clr[newa][newb] = true;
            Q.push({newa,newb});
        }
    }
    if(isInf){
        cout << "INF\n";
    }else{
        cout << ans << "\n";
    }

    return 0;
}

Measured memory_bytes: 34512