//--------------------------------------------------
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2,popcnt,fma")
#pragma GCC optimize("fast-math")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Ofast")
//--------------------------------------------------
#include <bits/stdc++.h>
#include <chrono>
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <cassert>
#include <random>
#include <bitset>
#include <iomanip>
#include <numeric>
#include <time.h>
#include <ctime>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#include <stack>
#include <cstring>
//--------------------------------------------------
#define forn(i, n) for(int i = 0; i < n; i++)
#define forw(i, n) for(int i = n-1; i >= 0; --i)
#define forns(i, n, s) for(int i = s; i < n; i++)
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
//----------------------------------------------------
using namespace std;
//----------------------------------------------------
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;
typedef vector<ll> lnum;
typedef complex<ld> comp;
//----------------------------------------------------
const ll mod = 1e9 + 7, mod2 = 998244353;
const ld eps = 1e-6;
const ll inf = 1e18;
const int base = 1e9;
const ld PI = 3.1415926;
//----------------------------------------------------
#define endl '\n';
#ifdef MY_DEBUG
void deb(ld x) { cerr << x << endl; };
#else
void deb(ld x){};
#endif
//----------------------------------------------------
int n, m;
int vx1[3001], vx2[3001], vy[3001];
int hx[3001], hy1[3001], hy2[3001];
bool ngx[3001][3001], ngy[3001][3001];
vector<int> x, y;
queue<pair<int, int>> q;
ll ans = INT64_MAX;
//----------------------------------------------------
unsigned int bitcount(ull val) { return __builtin_popcount(val) + __builtin_popcount(val >> 32); }

void local() {
    freopen("test.in", "r", stdin);
}

void remote() {
}

void read() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n >> m;
    forn(i, n){
        int x1, x2, yy;
        cin >> x1 >> x2 >> yy;
        x.pb(x1), x.pb(x2), y.pb(yy);
        vx1[i] = x1;
        vx2[i] = x2;
        vy[i] = yy;
    }
    forn(i, m){
        int xx, yy, yyy;
        cin >> xx >> yy >> yyy;
        x.pb(xx), y.pb(yy), y.pb(yyy);
        hx[i] = xx;
        hy1[i] = yy;
        hy2[i] = yyy;
    }
}

int ind(int val, const vector<int> &v){
    return lower_bound(all(v), val) - v.begin();
}

int main() {
#ifdef MY_DEBUG
    local();
#else
    remote();
#endif
    read();

    sort(all(x));
    sort(all(y));
    x.erase(unique(all(x)), x.end()), y.erase(unique(all(y)), y.end());
    forn(i, n){
        int from = ind(vx1[i], x);
        int to = ind(vx2[i], x);
        int yy = ind(vy[i], y);
        forns(j, to, from) ngx[j][yy] = true;
    }
    forn(i, m){
        int from = ind(hy1[i], y);
        int to = ind(hy2[i], y);
        int xx = ind(hx[i], x);
        forns(j, to, from) ngy[xx][j] = true;
    }
    n = x.size(), m = y.size();

    int start_v = lower_bound(all(x), 0) - x.begin() - 1;
    int start_h = lower_bound(all(y), 0) - y.begin() - 1;
    q.push({start_v, start_h});

    ll ans = 0;
    vector<vector<bool>> u(n, vector<bool> (m, false));
    while(!q.empty()){
        const pair<int, int> &p = q.front();
        q.pop();
        int xx = p.x, yy = p.y;
        if(xx < 0 || xx >= n - 1 || yy < 0 || yy >= m - 1){
            cout << "INF" << endl;
            return 0;
        }
        if(u[xx][yy]) continue;
        ans += (ll) (x[xx+1] - x[xx]) * (y[yy+1] - y[yy]);
        u[xx][yy] = true;
        if(!ngx[xx][yy]) q.push({xx, yy-1});
        if(!ngx[xx][yy+1]) q.push({xx, yy+1});
        if(!ngy[xx][yy]) q.push({xx-1, yy});
        if(!ngy[xx+1][yy]) q.push({xx+1, yy});
    }

    cout << ans << endl;
}

Measured memory_bytes: 18952