#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int ,int>;
int compress(vector<ll> &x1, vector<ll> &x2, vector<ll> &x3, vector<ll> &xs)
{
    int n = x1.size();
    for(int i = 0; i < n; i++) xs.push_back(x1[i]); 
    n = x2.size();
    for(int i = 0; i < n; i++) xs.push_back(x2[i]); 
    n = x3.size();
    for(int i = 0; i < n; i++) xs.push_back(x3[i]); 
    xs.push_back(-1e10);
    xs.push_back(-1e10);
    xs.push_back(0);
    sort(xs.begin(), xs.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end());
    n = x1.size();
    for(int i = 0; i < n; i++) x1[i] = lower_bound(xs.begin(), xs.end(), x1[i]) - xs.begin();
    n = x2.size();
    for(int i = 0; i < n; i++) x2[i] = lower_bound(xs.begin(), xs.end(), x2[i]) - xs.begin();
    n = x3.size();
    for(int i = 0; i < n; i++) x3[i] = lower_bound(xs.begin(), xs.end(), x3[i]) - xs.begin();
    return xs.size();
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<ll> a(n);
    vector<ll> b(n);
    vector<ll> c(n);
    vector<ll> d(m);
    vector<ll> e(m);
    vector<ll> f(m);
    for(int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];
    for(int i = 0; i < m; i++) cin >> d[i] >> e[i] >> f[i];
    vector<ll> xc;
    vector<ll> yc;
    int h = compress(a, b, d, xc);
    int w = compress(c, e, f, yc);

    vector<vector<bool>> wallx(h, vector<bool>(w, false));
    vector<vector<bool>> wally(h, vector<bool>(w, false));
    for(int i = 0; i < n; i++)
    {
        for(int x = a[i]; x < b[i]; x++)
        {
            wallx[x][c[i]] = true;
        }
    }
    for(int i = 0; i < m; i++)
    {
        for(int y = e[i]; y < f[i]; y++)
        {
            wally[d[i]][y] = true;
        }
    }
    vector<vector<bool>> field(h, vector<bool>(w, false));
    queue<P> que;
    int posx = lower_bound(xc.begin(), xc.end(), 0) - xc.begin();
    int posy = lower_bound(yc.begin(), yc.end(), 0) - yc.begin();
    que.push(P(posx, posy));
    while(!que.empty())
    {
        int x = que.front().first;
        int y = que.front().second;
        que.pop();
        if(x == 0 || x == h-1 || y == 0 || y == w-1)
        {
            cout << "INF" << endl;
            return 0;
        }
        if(field[x][y]) continue;
        field[x][y] = true;
        if(!wallx[x][y+1]) que.push(P(x, y+1)); // r
        if(!wallx[x][y]) que.push(P(x, y-1));   // l
        if(!wally[x+1][y]) que.push(P(x+1, y)); // d
        if(!wally[x][y]) que.push(P(x-1, y));   // u
    }
    ll ans = 0;
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            if(field[i][j])
            {
                ans += (ll)(xc[i+1] - xc[i]) * (yc[j+1] - yc[j]);
            }
        }
    }
    cout << ans << endl;
}
