#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N, M;
    cin >> N >> M;
    int A[N], B[N], C[N];
    rep(i, N) cin >> A[i] >> B[i] >> C[i];
    int D[M], E[M], F[M];
    rep(i, M) cin >> D[i] >> E[i] >> F[i];
    map<int, int> mpx, mpy;
    mpx[-inf]++, mpx[inf]++, mpy[-inf]++, mpy[inf]++;
    mpx[0]++, mpy[0]++;
    rep(i, N){
        mpx[A[i]]++, mpx[B[i]]++, mpy[C[i]]++;
    }
    rep(i, M){
        mpx[D[i]]++, mpy[E[i]]++, mpy[F[i]]++;
    }
    int n = 0, m = 0;
    for(auto &e: mpx) e.second = n++;
    for(auto &e: mpy) e.second = m++;
    int xs[n], ys[m];
    for(auto &e: mpx) xs[e.second] = e.first;
    for(auto &e: mpy) ys[e.second] = e.first;
    bool es[n-1][m-1][4];
    rep(i, n-1) rep(j, m-1) rep(k, 4) es[i][j][k] = true;
    rep(i, N){
        int a = mpx[A[i]], b = mpx[B[i]], c = mpy[C[i]];
        rep2(j, a, b-1){
            es[j][c-1][3] = false;
            es[j][c][1] = false;
        }
    }
    rep(i, M){
        int d = mpx[D[i]], e = mpy[E[i]], f = mpy[F[i]];
        rep2(j, e, f-1){
            es[d-1][j][2] = false;
            es[d][j][0] = false;
        }
    }
    int ex[] = {-1, 0, 1, 0}, ey[] = {0, -1, 0, 1};
    ll dx[n-1], dy[m-1];
    rep(i, n-1) dx[i] = xs[i+1]-xs[i];
    rep(i, m-1) dy[i] = ys[i+1]-ys[i];
    int sx = mpx[0], sy = mpy[0];
    ll ans = 0;
    bool used[n-1][m-1];
    fill(used[0], used[n-1], false);
    queue<pii> que;
    que.push(pii(sx, sy));
    while(!que.empty()){
        int x = que.front().first, y = que.front().second;
        que.pop();
        if(used[x][y]) continue;
        if(x == 0 || x == n-2 || y == 0 || y == m-2){
            cout << "INF" << endl;
            return 0;
        }
        used[x][y] = true;
        ans += dx[x]*dy[y];
        rep(k, 4){
            int nx = x+ex[k], ny = y+ey[k];
            if(!es[x][y][k] || used[nx][ny]) continue;
            que.push(pii(nx, ny));
        }
    }
    cout << ans << endl;
}