#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1005;
const int M = 7005;
int a[N], b[N], c[N], d[N], e[N], f[N];
vector<int> vx, vy;
int dx[] = {0, 0, -1, 1}, dy[] = {-1, 1, 0, 0};
bool ma[M][M], vis[M][M];
int get_x(int x) {
    return lower_bound(vx.begin(), vx.end(), x) - vx.begin();
}
int get_y(int x) {
    return lower_bound(vy.begin(), vy.end(), x) - vy.begin();
}
int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    vx.push_back(-1.1e9), vx.push_back(0);
    vy.push_back(-1.1e9), vy.push_back(0);
    for(int i = 0; i < n; i++) {
        scanf("%d%d%d", &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++) {
        scanf("%d%d%d", &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 = 2 * e[i] - 1; j < 2 * f[i]; j++) {
            ma[2 * d[i] - 1][j] = true;
        }
    }
    int sx = get_x(0) * 2 - 1, sy = get_y(0) * 2 - 1;
    bool flag = false;
    ll ans = 0;
    queue<pair<int, int>> qu;
    qu.push({sx, sy}), vis[sx][sy] = true;
    while(!qu.empty()) {
        int ux = qu.front().first, uy = qu.front().second;
        qu.pop();
        if(ux == M - 1 || uy == M - 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 >= M || xx < 0 || yy >= M || yy < 0 || vis[xx][yy] || ma[xx][yy]) continue;
            qu.push({xx, yy}), vis[xx][yy] = true;
        }
    }
    if(flag) printf("INF\n");
    else printf("%lld\n", ans);
    return 0;
}
