/************************************************
   Start coding only after you have clear idea. 
*************************************************/

#include <bits/stdc++.h>

#define x first
#define y second
#define pii pair<int,int>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
const int maxm = 3e3+23;
const int maxn = 2e5+35;
int a[maxm],b[maxm],c[maxm],d[maxm],e[maxm],f[maxm];
vector<int> x,y;
int D[maxm][maxm],U[maxm][maxm],L[maxm][maxm],R[maxm][maxm];
inline int getx(int val){
    return lower_bound(all(x),val) - x.begin() + 1;
}
inline int gety(int val){
    return lower_bound(all(y),val) - y.begin() + 1;
}
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
bool check(int fx,int fy){
    return fx>0&&fx<=sz(x)&&fy>0&&fy<=sz(y);
}
int vis[maxm][maxm];
LL solve(int sx,int sy){
    queue<pii> q; q.push(pii(sx,sy)); vis[sx][sy] = 1; 
    LL ans = 0;
    while(!q.empty()){
        pii now = q.front(); q.pop();
        ans += 1ll*(x[now.x]-x[now.x-1])*(y[now.y]-y[now.y-1]);
        for(int i = 0;i < 4; ++i){
            if(i==0&&U[now.x][now.y]) continue;
            if(i==1&&D[now.x][now.y]) continue;
            if(i==2&&R[now.x][now.y]) continue;
            if(i==3&&L[now.x][now.y]) continue;
            int fx = now.x+dx[i],fy = now.y+dy[i];
            if(check(fx,fy)){
                if(!vis[fx][fy]){
                    vis[fx][fy] = 1;
                    q.push(pii(fx,fy));
                }
            }
            else return -1;
        }
    }
    return ans;
}
int main(){
    int n,m; scanf("%d %d",&n,&m);
    for(int i = 1;i <= n; ++i){
        scanf("%d %d %d",a+i,b+i,c+i);
        x.push_back(a[i]);
        x.push_back(b[i]);
        y.push_back(c[i]);
    }
    for(int i = 1;i <= m; ++i){
        scanf("%d %d %d",d+i,e+i,f+i);
        x.push_back(d[i]);
        y.push_back(e[i]);
        y.push_back(f[i]);
    }
    x.push_back(0); y.push_back(0);
    sort(all(x)); sort(all(y));
    x.erase(unique(all(x)),x.end());
    y.erase(unique(all(y)),y.end());
    for(int i = 1;i <= n; ++i){
        a[i] = getx(a[i]);b[i] = getx(b[i]);c[i] = gety(c[i]);
        for(int j = a[i];j < b[i]; ++j){
            U[j][c[i]-1] = 1;
            D[j][c[i]] = 1;
        }
    }
    for(int i = 1;i <= m; ++i){
        d[i] = getx(d[i]);e[i] = gety(e[i]);f[i] = gety(f[i]);
        for(int j = e[i];j < f[i]; ++j){
            L[d[i]][j] = 1;
            R[d[i]-1][j] = 1;
        }
    }
    LL res = solve(getx(0),gety(0));
    if(res == -1) puts("INF");
    else cout << res << '\n';
    return 0;
}