#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T = int> void print(vector<T> v){for(auto a:v)cout<<a<<" ";cout<<endl;}

/*
座圧して取れるだけ取ればok
*/

bool inf=false;
ll n,m,a[1010],b[1010],c[1010],d[1010],e[1010],f[1010], xs, ys, ans=0;
ll dx[]={0,1,0,-1},dy[]={1,0,-1,0};
ll ar[6010][6010];
V<ll> w,h;
map<ll,ll> w_i,h_i;

int main(void){
	cin>>n>>m;
	rep(i,n)cin>>a[i]>>b[i]>>c[i];
	rep(i,m)cin>>d[i]>>e[i]>>f[i];
	rep(i,n){
		w.push_back(a[i]);
		w.push_back(b[i]);
		h.push_back(c[i]);
	}
	rep(i,m){
		w.push_back(d[i]);
		h.push_back(e[i]);
		h.push_back(f[i]);
	}
	h.push_back(-2e9);  // 番兵
	h.push_back(2e9);  //
	w.push_back(-2e9);  //
	w.push_back(2e9);  //
	sort(h.begin(), h.end());
	sort(w.begin(), w.end());
	h.erase(unique(h.begin(), h.end()), h.end());  // 重複削除
	w.erase(unique(w.begin(), w.end()), w.end());  //
	rep(i,h.size()){
		h_i[h[i]]=i;
		if(h[i]<=0){  // 初期位置の計算
			ys=i;
		}
	}
	rep(i,w.size()){
		w_i[w[i]]=i;
		if(w[i]<=0){  //
			xs=i;
		}
	}
	xs=(xs+1)*2;  //
	ys=(ys+1)*2;  //
	rep(i,n){
		ll y = h_i[c[i]]*2+1;
		reg(x,w_i[a[i]]*2+1, w_i[b[i]]*2+1)ar[y][x] = 1;  // 線分を塗る
	}
	rep(i,m){
		ll x = w_i[d[i]]*2+1;
		reg(y,h_i[e[i]]*2+1, h_i[f[i]]*2+1)ar[y][x] = 1;  //
	}
	queue<pair<ll,ll>> q;
	q.push({ys, xs});
	ar[ys][xs] = 2;
	// rep(i,2*h.size()+1){
	// 	rep(j,2*w.size()+1){
	// 		cerr<<ar[i][j];
	// 	}
	// 	cerr<<endl;
	// }
	while(not q.empty()){  // dfsで通る場所を求める
		auto p = q.front();q.pop();
		ll y=p.first, x=p.second;
		if(x==0 || y==0 || x==w.size()*2 || y==h.size()*2){  // 外側に到達したら無限
			inf=true;
			break;
		}
		if(x%2==0 && y%2==0){
			ans += (w[x/2]-w[x/2-1]) * (h[y/2]-h[y/2-1]);
		}
		rep(i,4){
			if(ar[y+dy[i]][x+dx[i]]==0){
				ar[y+dy[i]][x+dx[i]]=3;
				q.push({y+dy[i],x+dx[i]});
			}
		}
	}
	if(inf){
		cout<<"INF"<<endl;
	}else{
		cout<<ans<<endl;
	}
	return 0;
}