// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 30;
const ll MOD = 1000000007LL;
 
int main() {
    int N, M; scanf("%d%d", &N, &M);

    vector<ll> comp_x, comp_y;
    vector<ll> A(N), B(N), C(N);
    vector<ll> D(M), E(M), F(M);
    for(int i=0; i<N; i++) {
        scanf("%lld%lld%lld", &A[i], &B[i], &C[i]);
        comp_x.emplace_back(A[i]);
        comp_x.emplace_back(B[i]);
        comp_y.emplace_back(C[i]);
    }
    for(int i=0; i<M; i++) {
        scanf("%lld%lld%lld", &D[i], &E[i], &F[i]);
        comp_y.emplace_back(E[i]);
        comp_y.emplace_back(F[i]);
        comp_x.emplace_back(D[i]);
    }

    comp_x.emplace_back(-INF);
    comp_x.emplace_back(+INF);
    comp_x.emplace_back(0);
    sort(comp_x.begin(), comp_x.end());
    comp_x.erase(unique(comp_x.begin(), comp_x.end()), comp_x.end());

    comp_y.emplace_back(-INF);
    comp_y.emplace_back(+INF);
    comp_y.emplace_back(0);
    sort(comp_y.begin(), comp_y.end());
    comp_y.erase(unique(comp_y.begin(), comp_y.end()), comp_y.end());

    int N1 = comp_x.size(), N2 = comp_y.size();
    vector< vector<bool> > can_move(2*N1, vector<bool>(2*N2, true));
    vector< vector<bool> > visited(2*N1, vector<bool>(2*N2));
    vector<ll> cx(2*N1+1), cy(2*N2+1);
    
    for(int i=0; i<N; i++) {
        int xl = lower_bound(comp_x.begin(), comp_x.end(), A[i]) - comp_x.begin();
        int xr = lower_bound(comp_x.begin(), comp_x.end(), B[i]) - comp_x.begin();
        int y = lower_bound(comp_y.begin(), comp_y.end(), C[i]) - comp_y.begin();
        xl <<= 1, xr <<= 1, y <<= 1;
        for(int x=xl; x<=xr; x++) {
            can_move[x][y] = false;
        }
    }
    for(int i=0; i<M; i++) {
        int yl = lower_bound(comp_y.begin(), comp_y.end(), E[i]) - comp_y.begin();
        int yr = lower_bound(comp_y.begin(), comp_y.end(), F[i]) - comp_y.begin();
        int x = lower_bound(comp_x.begin(), comp_x.end(), D[i]) - comp_x.begin();
        yl <<= 1, yr <<= 1, x <<= 1;
        for(int y=yl; y<=yr; y++) {
            can_move[x][y] = false;
        }
    }

    /*
    for(int i=0; i<2*N1; i++) {
        for(int j=0; j<2*N2; j++) {
            fprintf(stderr, "%c%c", "#."[can_move[i][j]], " \n"[j + 1 == 2*N2]);
        }
    }
    */
    
    for(int i=0; i+1<N1; i++) {
        ll x1 = comp_x[i], x2 = comp_x[i+1];
        int k = (i << 1) | 1;
        cx[k] = x2 - x1;
    }
    for(int i=0; i+1<N2; i++) {
        ll y1 = comp_y[i], y2 = comp_y[i+1];
        int k = (i << 1) | 1;
        cy[k] = y2 - y1;
    }

    const ll LIM = 1LL << 62;
    ll ans = 0;
    queue< pair<int, int> > que;
    {
        int x = lower_bound(comp_x.begin(), comp_x.end(), 0LL) - comp_x.begin();
        int y = lower_bound(comp_y.begin(), comp_y.end(), 0LL) - comp_y.begin();
        x = (x << 1) | 1, y = (y << 1) | 1;

        visited[x][y] = true;
        ans += cx[x] * cy[y];
        chmin(ans, LIM);
        que.emplace(x, y);
    }

    while(que.size()) {
        int x, y; tie(x, y) = que.front(); que.pop();
        for(int k=0; k<4; k++) {
            int nx = x + dx[k], ny = y + dy[k];
            if(nx < 0 or nx >= 2*N1 or ny < 0 or ny >= 2*N2) continue;
            if(visited[nx][ny] or !can_move[nx][ny]) continue;
            visited[nx][ny] = true;
            ans += cx[nx] * cy[ny];
            chmin(ans, LIM);
            que.emplace(nx, ny);
        }
    }

    {
        vector<ll> chk = {-INF, +INF};
        for(auto e : chk) {
            int kx = lower_bound(comp_x.begin(), comp_x.end(), e) - comp_x.begin();
            kx = (kx << 1) | 1;
            for(int i=0; i<2*N2; i++) if(visited[kx][i]) ans = LIM;

            int ky = lower_bound(comp_y.begin(), comp_y.end(), e) - comp_y.begin();
            ky = (ky << 1) | 1;
            for(int i=0; i<2*N1; i++) if(visited[i][ky]) ans = LIM;
        }
    }

    if(ans >= LIM) puts("INF");
    else printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 12980