#include<bits/stdc++.h>

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

#define MOD 1000000007
#define INF 1001001001

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

int main(int, char**)
{
    int n, m;
    cin >> n >> m;

    vector< pair<int, P> > line[2];
    vector<int> grid[2];

    int idx, s, e, k;
    rep(i,2) {
        k = i ? m : n;
        rep(j,k) {
            if (i) { cin >> idx >> s >> e; }
            else { cin >> s >> e >> idx; }
            grid[i].push_back(idx);
            line[i].emplace_back(idx, P(s, e));
        }
    }
    int sz[2];
    rep(i,2) {
        grid[i].push_back(0);
        sort(grid[i].begin(), grid[i].end());
        grid[i].erase( unique(grid[i].begin(), grid[i].end()), grid[i].end());
        sz[i] = grid[i].size();
    }
    vector< vector<int> > area(sz[0]*2, vector<int>(sz[1]*2, 0));

    rep(i,2) {
        for (auto l : line[i]) {
            auto itr = lower_bound(grid[i].begin(), grid[i].end(), l.first);
            int li = distance(grid[i].begin(), itr);
            itr = lower_bound(grid[!i].begin(), grid[!i].end(), l.second.first);
            int d1 = distance(grid[!i].begin(), itr);
            itr = lower_bound(grid[!i].begin(), grid[!i].end(), l.second.second+1);
            int d2 = distance(grid[!i].begin(), itr);
            rep(j,(d2-d1)*2-1) {
                int idx1 = li*2;
                int idx2 = d1*2+j;
                if (i) swap(idx1, idx2);
                area[idx1][idx2] = 1;
            }
        }
    }
    int st[2];
    rep(i,2) {
        auto itr = lower_bound(grid[i].begin(), grid[i].end(), 0);
        st[i] = distance(grid[i].begin(), itr) * 2;
    }
    ll ans = 0;
    queue<P> q;
    q.emplace(st[0],st[1]);
    while (!q.empty()) {
        int x = q.front().first;
        int y = q.front().second;
        q.pop();
        if (area[x][y]) continue;
        if (x == 0 || y == 0 || x >= (sz[0]-1)*2 || y >= (sz[1]-1)*2) {
            cout << "INF" << endl;
            return 0;
        }
        if (x % 2 && y % 2) {
            ll v = grid[0][x/2+1] - grid[0][x/2];
            ll h = grid[1][y/2+1] - grid[1][y/2];
            ans += v * h; 
        }
        rep(i,4) {
            int nx = x;
            int ny = y;
            int dir = (i % 2) ? 1 : -1;
            if (i / 2) nx += dir;
            else ny += dir;
            if (!area[nx][ny]) q.emplace(nx,ny);
        }
        area[x][y] = 1;
    }

    cout << ans << endl;

    return 0;
}