#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
lint inf=1001001001;
vector<lint> x,y;
int xn,yn;
lint a[1010],b[1010],c[1010],d[1010],e[1010],f[1010];
bool xb[4010][4010],yb[4010][4010],sumi[4010][4010];
void dfs(int u,int v){
	sumi[u][v]=true;
	//cout<<"("<<x[u]<<","<<y[v]<<")-("<<x[u+1]<<","<<y[v+1]<<")"<<endl;
	if(u>0 && !xb[u][v] && !sumi[u-1][v]) dfs(u-1,v);
	if(v>0 && !yb[u][v] && !sumi[u][v-1]) dfs(u,v-1);
	if(u<xn-2 && !xb[u+1][v] && !sumi[u+1][v]) dfs(u+1,v);
	if(v<yn-2 && !yb[u][v+1] && !sumi[u][v+1]) dfs(u,v+1);
}
int main()
{
	int n,m;
	x.pb(0);y.pb(0);x.pb(inf);y.pb(inf);x.pb(-inf);y.pb(-inf);
	cin>>n>>m;
	rep(i,n){
		cin>>a[i]>>b[i]>>c[i];
		x.pb(a[i]);x.pb(b[i]);y.pb(c[i]);
	}
	rep(i,m){
		cin>>d[i]>>e[i]>>f[i];
		x.pb(d[i]);y.pb(e[i]);y.pb(f[i]);
	}
	sort(All(x));x.erase(unique(All(x)),x.end());
	sort(All(y));y.erase(unique(All(y)),y.end());
	xn=x.size();yn=y.size();
	memset(xb,false,sizeof(xb));
	memset(yb,false,sizeof(yb));
	rep(i,n){
		int xs=lower_bound(All(x),a[i])-x.begin();
		int xg=lower_bound(All(x),b[i])-x.begin();
		int ys=lower_bound(All(y),c[i])-y.begin();
		REP(j,xs,xg) yb[j][ys]=true;
	}
	rep(i,m){
		int ys=lower_bound(All(y),e[i])-y.begin();
		int yg=lower_bound(All(y),f[i])-y.begin();
		int xs=lower_bound(All(x),d[i])-x.begin();
		REP(j,ys,yg) xb[xs][j]=true;
	}
	memset(sumi,false,sizeof(sumi));
	dfs(lower_bound(All(x),0L)-x.begin(),lower_bound(All(y),0L)-y.begin());
	lint out=0;
	rep(i,xn-1) rep(j,yn-1){
		if(sumi[i][j]) out+=(x[i+1]-x[i])*(y[j+1]-y[j]);
	}
	if(out>=inf*inf) cout<<"INF"<<endl;
	else cout<<out<<endl;
}
