#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

// 柵にも幅を1持たせる
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int main() {
    int n, m;
    cin >> n >> m;
    int a[n], b[n], c[n], d[m], e[m], f[m];
    vector<int> u,v;
    rep(i,n){
        cin >> a[i] >> b[i] >> c[i];
        a[i] *= 2; b[i] *= 2; c[i] *= 2;
        u.push_back(a[i]);
        u.push_back(b[i]);
        v.push_back(c[i]);
    }
    rep(i,m){
        cin >> d[i] >> e[i] >> f[i];
        d[i] *= 2; e[i] *= 2; f[i] *= 2;
        u.push_back(d[i]);
        v.push_back(e[i]);
        v.push_back(f[i]);
    }

    sort(u.begin(), u.end());
    u.erase(unique(u.begin(), u.end()), u.end());
    int num = u.size();
    u.push_back(u[0]-1);
    rep(i,num){
        u.push_back(u[i]+1);
    }

    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    num = v.size();
    v.push_back(v[0]-1);
    rep(i,num){
        v.push_back(v[i]+1);
    }

    sort(u.begin(), u.end());
    sort(v.begin(), v.end());

    int h = u.size();
    int w = v.size();
    int g[h][w];
    rep(i,h)rep(j,w)g[i][j] = 0;
    
    rep(i,n){
        int x1 = lower_bound(u.begin(),u.end(),a[i]) - u.begin();
        int x2 = lower_bound(u.begin(), u.end(), b[i]) - u.begin();
        int y = lower_bound(v.begin(), v.end(), c[i]) - v.begin();
        srep(j,x1,x2+1) g[j][y] = 1;
    }
    rep(i,m){
        int x = lower_bound(u.begin(),u.end(),d[i]) - u.begin();
        int y1 = lower_bound(v.begin(), v.end(), e[i]) - v.begin();
        int y2 = lower_bound(v.begin(), v.end(), f[i]) - v.begin();
        srep(j,y1,y2+1) g[x][j] = 1;
    }

    int sx = lower_bound(u.begin(), u.end(), 0) - u.begin();
    if(u[sx]%2==0)sx--;
    int sy = lower_bound(v.begin(),v.end(),0) - v.begin();
    if(v[sy]%2==0)sy--;

    g[sx][sy] = 2;
    if(sx == 0 || sx == h-1 || sy == 0 || sy == w-1){
        cout << "INF" << endl;
        return 0;
    }

    queue<P> que;
    que.push(P(sx, sy));
    while(que.size()>0){
        int x = que.front().first;
        int y = que.front().second;
        que.pop();
        rep(i,4){
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(nx == 0 || nx == h-1 || ny == 0 || ny == w-1){
                cout << "INF" << endl;
                return 0;
            }
            if(g[nx][ny] == 0){
                g[nx][ny] = 2;
                que.push(P(nx,ny));
            }
        }
    }

    ll ans = 0;
    rep(i,h){
        rep(j,w){
            // cout << g[i][j];
            if(g[i][j] == 2 && i % 2 == 0 && j % 2 == 0){
                ll x1 = u[i-1], x2 = u[i+1];
                ll y1 = v[j-1], y2 = v[j+1];
                ans += (x2-x1)/2 * (y2-y1)/2;
            }
        }
        // cout << endl;
    }

    cout << ans << endl;
    return 0;
}


