#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 3010;

int n, m, a[1010], b[1010], c[1010], d[1010], e[1010], f[1010];
vector<pii> vertical[MAX], horizontal[MAX];
vector<int> vx, vy;
bool used[MAX][MAX];

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};

int x_id(int x){
    return lower_bound(vx.begin(), vx.end(), x) - vx.begin();
}

int y_id(int y){
    return lower_bound(vy.begin(), vy.end(), y) - vy.begin();
}

bool check_horizontal(int x, int l, int r){
    auto seg = prev(lower_bound(horizontal[x].begin(), horizontal[x].end(), pii(r, -mod)));
    return seg->se <= l;
}

bool check_vertical(int y, int l, int r){
    auto seg = prev(lower_bound(vertical[y].begin(), vertical[y].end(), pii(r, -mod)));
    return seg->se <= l;
}

bool check(int xi, int yi, int dir){
    if(dir == 0) return check_horizontal(xi, vy[yi], vy[yi+1]);
    else if(dir == 1) return check_vertical (yi, vx[xi], vx[xi+1]);
    else if(dir == 2) return check_horizontal(xi+1, vy[yi], vy[yi+1]);
    else return check_vertical(yi+1, vx[xi], vx[xi+1]);
}

int main(){
    scanf("%d%d", &n, &m);
    rep(i, n){
        scanf("%d%d%d", &a[i], &b[i], &c[i]);
        vx.push_back(a[i]);
        vx.push_back(b[i]);
        vy.push_back(c[i]);
    }
    rep(i, m){
        scanf("%d%d%d", &d[i], &e[i], &f[i]);
        vx.push_back(d[i]);
        vy.push_back(e[i]);
        vy.push_back(f[i]);
    }
    vx.push_back(0); vx.push_back(-mod); vx.push_back(mod);
    vy.push_back(0); vy.push_back(-mod); vy.push_back(mod);
    sort(vx.begin(), vx.end());
    vx.erase(unique(vx.begin(), vx.end()), vx.end());
    sort(vy.begin(), vy.end());
    vy.erase(unique(vy.begin(), vy.end()), vy.end());

    rep(i, n) vertical[y_id(c[i])].emplace_back(a[i], b[i]);
    rep(i, m) horizontal[x_id(d[i])].emplace_back(e[i], f[i]);
    rep(i, MAX){
        vertical[i].emplace_back(-mod-10, -mod);
        vertical[i].emplace_back(mod, mod+10);
        sort(vertical[i].begin(), vertical[i].end());
        vector<pii> tmp;
        for(auto p: vertical[i]){
            if(!tmp.empty() && tmp.rbegin()->se >= p.fi){
                chmax(tmp.rbegin()->se, p.se);
            }
            else tmp.push_back(p);
        }
        swap(vertical[i], tmp);
    }
    rep(i, MAX){
        horizontal[i].emplace_back(-mod-10, -mod);
        horizontal[i].emplace_back(mod, mod+10);
        sort(horizontal[i].begin(), horizontal[i].end());
        vector<pii> tmp;
        for(auto p: horizontal[i]){
            if(!tmp.empty() && tmp.rbegin()->se >= p.fi){
                chmax(tmp.rbegin()->se, p.se);
            }
            else tmp.push_back(p);
        }
        swap(horizontal[i], tmp);
    }

    lint ans = 0;
    queue<pii> que;
    que.emplace(x_id(0), y_id(0));
    used[x_id(0)][y_id(0)] = true;
    while(!que.empty()){
        auto [xi, yi] = que.front();
        que.pop();
        if(vx[xi] == -mod || vx[xi+1] == mod || vy[yi] == -mod || vy[yi+1] == mod){
            puts("INF");
            return 0;
        }
        ans += (lint)(vx[xi+1] - vx[xi]) * (vy[yi+1] - vy[yi]);

        rep(i, 4){
            if(!check(xi, yi, i)) continue;
            int nx = xi + dx[i], ny = yi + dy[i];
            if(used[nx][ny]) continue;
            if(vx[nx] == -mod || vx[nx+1] == mod || vy[ny] == -mod || vy[ny] == mod){
                puts("INF");
                return 0;
            }
            que.emplace(nx, ny);
            used[nx][ny] = true;
        }
    }

    printf("%lld\n", ans);
}

Measured memory_bytes: 12860