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

typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M;
    cin >> N >> M;
    map<int,int> xmp, ymp;
    vector<int> A(N),B(N),C(N);
    vector<int> D(M),E(M),F(M);
    xmp[0] = 0;
    ymp[0] = 0;
    for (int i=0;i<N;i++){
        cin >> A[i] >> B[i] >> C[i];
        xmp[A[i]] = 0;
        xmp[B[i]] = 0;
        ymp[C[i]] = 0;
    }
    for (int i=0;i<M;i++){
        cin >> D[i] >> E[i] >> F[i];
        ymp[E[i]] = 0;
        ymp[F[i]] = 0;
        xmp[D[i]] = 0;
    }
    vector<int> xs, ys;
    for (auto& p : xmp){
        p.second = xs.size();
        xs.push_back(p.first);
    }
    for (auto& p : ymp){
        p.second = ys.size();
        ys.push_back(p.first);
    }

    int X = xs.size()*2;
    int Y = ys.size()*2;

    vector<vector<int>> s = vector<vector<int>>(X,vector<int>(Y));
    for (int i=0;i<N;i++){
        int a = 2*xmp[A[i]];
        int b = 2*xmp[B[i]];
        int c = 2*ymp[C[i]];
        for (int x=a;x<=b;x++) s[x][c] = -1;
    }
    for (int i=0;i<M;i++){
        int e = 2*ymp[E[i]];
        int f = 2*ymp[F[i]];
        int d = 2*xmp[D[i]];
        for (int y=e;y<=f;y++) s[d][y] = -1;
    }
    
    queue<pair<int,int>> q;
    q.push(make_pair(xmp[0]*2,ymp[0]*2));
    s[xmp[0]*2][ymp[0]*2] = 1;
    while (!q.empty()){
        pair<int,int> p = q.front();q.pop();
        for (int d=0;d<4;d++){
            int nx = p.first + dx[d];
            int ny = p.second + dy[d];
            if (nx < 0 || nx >= X || ny < 0 || ny >= Y) continue;
            if (s[nx][ny] != 0) continue;
            s[nx][ny] = 1;
            q.push(make_pair(nx,ny));
        }
    }
    ll ans = 0;
    for (int x=0;x<X;x++){
        for (int y=0;y<Y;y++){
            if (s[x][y] != 1) continue;
            if (x==0||x==X-1||y==0||y==Y-1){
                cout << "INF" << "\n";
                return 0;
            }
            if (x%2 == 0 || y%2 == 0) continue;
            ans += 1LL*(xs[x/2+1] - xs[x/2])*(ys[y/2+1] - ys[y/2]);
        }
    }
    cout << ans << "\n";
}