#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1005;
const int maxm = 7005;

int a[maxn], b[maxn], c[maxn], d[maxn], e[maxn], f[maxn];
vector <int> vx, vy;
int dx[] = {0, 0, -1, 1}, dy[] = {-1, 1, 0, 0};
bool vis[maxm][maxm], ma[maxm][maxm];

int get_x(int val){
    return lower_bound(vx.begin(), vx.end(), val) - vx.begin();
}

int get_y(int val){
    return lower_bound(vy.begin(), vy.end(), val) - vy.begin();
}

int main(){
    int n, m; scanf("%d%d", &n, &m);
    vx.push_back(0), vy.push_back(0);
    vx.push_back(-1.1e9), vy.push_back(-1.1e9);

    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i] >> c[i];
        vx.push_back(a[i]), vx.push_back(b[i]);
        vy.push_back(c[i]);
    }

    for(int i = 0; i < m; i++){
        cin >> d[i] >> e[i] >> f[i];
        vy.push_back(e[i]), vy.push_back(f[i]);
        vx.push_back(d[i]);
    }

    sort(vx.begin(), vx.end()), vx.erase(unique(vx.begin(), vx.end()), vx.end());

    sort(vy.begin(), vy.end()), vy.erase(unique(vy.begin(), vy.end()), vy.end());


    for(int i = 0; i < n; i++){
        a[i] = get_x(a[i]), b[i] = get_x(b[i]), c[i] = get_y(c[i]);
        for(int j = a[i]*2 - 1; j < 2 * b[i]; j++)
            ma[j][2*c[i] - 1] = true;
    }

    for(int i = 0; i < m; i++){
        d[i] = get_x(d[i]), e[i] = get_y(e[i]), f[i] = get_y(f[i]);
        for(int j = e[i]*2-1; j < f[i]*2; j++)
            ma[2*d[i]-1][j] = true;
    }

    int sx = get_x(0)*2 - 1, sy = get_y(0)*2 - 1;

    queue<pair<int, int>> qu;
    qu.push({sx, sy}), vis[sx][sy] = true;
    ll ans = 0;
    bool flag = false;
    while(!qu.empty()){
        int ux = qu.front().first, uy = qu.front().second; qu.pop();
        if(ux == maxm-1 || uy == maxm-1 || ux == 0 || uy == 0){
            flag = true;
            break;
        }
        if(ux % 2 == 0 && uy % 2 == 0){
            int x = ux / 2, y = uy / 2;
            ans += 1ll * (vx[x + 1] - vx[x]) * (vy[y + 1] - vy[y]);
        }
        for(int i = 0; i < 4; i++){
            int xx = ux + dx[i], yy = uy + dy[i];
            if(xx >= maxm || xx < 0 || yy >= maxm || yy < 0 || ma[xx][yy] || vis[xx][yy]) continue;
            qu.push({xx, yy});
            vis[xx][yy] = true;
        }
    }
    if(flag) printf("INF\n");
    else printf("%lld\n", ans);
    return 0;
}
