#include <bits/stdc++.h>
using namespace std;

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

    vector<int> a(n), b(n), c(n), d(m), e(m), f(m);
    map<int, int> x, y;
    x[0] = 0;
    y[0] = 0;

    for(int i=0; i<n; i++){
        cin >> a[i] >> b[i] >> c[i];
        x[a[i]] = 0;// value will be determined later
        x[b[i]] = 0;
        y[c[i]] = 0;
    }
    for(int i=0; i<m; i++){
        cin >> d[i] >> e[i] >> f[i];
        x[d[i]] = 0;
        y[e[i]] = 0;
        y[f[i]] = 0;
    }

    vector<int> xs, ys;
    for(auto& xi : x){
        xi.second = xs.size();// value = order (since sorted in map)
        xs.push_back(xi.first);
    }
    for(auto& yi : y){
        yi.second = ys.size();
        ys.push_back(yi.first);
    }

    int h = xs.size() * 2;
    int w = ys.size() * 2;

    vector<vector<int>> grid(h, vector<int>(w));// 1: visited, 0: not yet, -1 : wall
    for(int i=0; i<n; i++){
        int ai = x[a[i]] * 2;
        int bi = x[b[i]] * 2;
        int ci = y[c[i]] * 2;
        for(int xx=ai; xx<=bi; xx++){
            grid[xx][ci] = -1;
        }
    }
    for(int i=0; i<m; i++){
        int di = x[d[i]] * 2;
        int ei = y[e[i]] * 2;
        int fi = y[f[i]] * 2;
        for(int yy=ei; yy<=fi; yy++){
            grid[di][yy] = -1;
        }
    }

    // BFS
    queue<pair<int, int>> q;
    int sx = x[0] * 2;
    int sy = y[0] * 2;
    grid[sx][sy] = 1;
    q.push({sx,sy});

    vector<int> dx = {1, 0, -1, 0};
    vector<int> dy = {0, 1, 0, -1};

    while(q.empty() == false){
        int x_current = q.front().first;
        int y_current = q.front().second;
        q.pop();

        for(int i=0; i<4; i++){
            int nx = x_current + dx[i];
            int ny = y_current + dy[i];
            if(0 <= nx && nx < h
            && 0 <= ny && ny < w
            && grid[nx][ny] == 0){
                grid[nx][ny] = 1;
                q.push({nx, ny});
            }
        }
    }

    /*
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cout << setw(3) << grid[i][j];
        }
        cout << endl;
    }
    */

    long long int ans = 0;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(grid[i][j] == 0 || grid[i][j] == -1) continue;// unreachable

            // else (reachable)
            if(i == 0 || i == h-1
            || j == 0 || j == w-1){
                cout << "INF" << endl;
                return 0;
            }

            if(i % 2 == 0 || j % 2 == 0) continue;// wall, regarded as (area) = 0
            long long int lx = xs[i/2+1] - xs[i/2];
            long long int ly = ys[j/2+1] - ys[j/2];
            ans += lx * ly;
        }
    }
    cout << ans << endl;
    return 0;
}