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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef pair<int, int> pi;

const int maxn = 3005;

int n, m;
int a[maxn], b[maxn], c[maxn], d[maxn], e[maxn], f[maxn];
int h, w;
int x[maxn], y[maxn];
int row[maxn][maxn], col[maxn][maxn];

bool vis[maxn][maxn];

bool in(int x, int y){
    return x >= 0 and y >= 0 and x <= h and y <= w;
}

void input(){
    cin >> n >> m;
    h = w = 0;
    for(int i = 1;i <= n;i++){
        cin >> a[i] >> b[i] >> c[i];
        x[++h] = a[i];
        x[++h] = b[i];
        y[++w] = c[i];
    }
    for(int i = 1;i <= m;i++){
        cin >> d[i] >> e[i] >> f[i];
        x[++h] = d[i];
        y[++w] = e[i];
        y[++w] = f[i];
    }
    sort(x + 1, x + h + 1);
    sort(y + 1, y + w + 1);
    h = unique(x + 1, x + 1 + h) - x - 1;
    w = unique(y + 1, y + 1 + w) - y - 1;
    for(int i = 1;i <= n;i++){
        a[i] = lower_bound(x + 1, x + 1 + h, a[i]) - x;
        b[i] = lower_bound(x + 1, x + 1 + h, b[i]) - x;
        c[i] = lower_bound(y + 1, y + 1 + w, c[i]) - y;
        row[c[i]][a[i]]++;
        row[c[i]][b[i]]--;
    }
    for(int i = 1;i <= m;i++){
        d[i] = lower_bound(x + 1, x + 1 + h, d[i]) - x;
        e[i] = lower_bound(y + 1, y + 1 + w, e[i]) - y;
        f[i] = lower_bound(y + 1, y + 1 + w, f[i]) - y;
        col[d[i]][e[i]]++;
        col[d[i]][f[i]]--;
    }
    for(int i = 1;i <= w;i++){
        row[i][0] = 0;
        for(int j = 1;j <= h;j++){
            row[i][j] += row[i][j - 1];
        }
    }
    for(int i = 1;i <= h;i++){
        col[i][0] = 0;
        for(int j = 1;j <= w;j++){
            col[i][j] += col[i][j - 1];
        }
    }
}

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

void solve(int sx, int sy){
    queue<pi> q;
    vis[sx][sy] = true;
    q.push(mp(sx, sy));
    while(!q.empty()){
        pi p = q.front(); q.pop();
        int x = p.fi;
        int y = p.se;
        for(int i = 0;i < 4;i++){
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(in(nx, ny) and !vis[nx][ny]){
                if(i & 1){
                    if(col[max(nx, x)][y] == 0){
                        vis[nx][ny] = true;
                        q.push(mp(nx, ny));
                    }
                }else{
                    if(row[max(ny, y)][x] == 0){
                        vis[nx][ny] = true;
                        q.push(mp(nx, ny));
                    }
                }
            }
        }
    }
    long long ans = 0;
    for(int i = 0;i <= h;i++){
        for(int j = 0;j <= w;j++){
            if(vis[i][j]){
                if(i == 0 or i == h or j == 0 or j == w){
                    cout << "INF" << endl;
                    return;
                }
                ans += 1LL * (x[i + 1] - x[i]) * (y[j + 1] - y[j]);
            }
        }
    }
    cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    input();
    int sx = upper_bound(x + 1, x + 1 + h, 0) - x - 1;
    int sy = upper_bound(y + 1, y + 1 + w, 0) - y - 1;
    solve(sx, sy);
    return 0;
}


Measured memory_bytes: 82944