#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;



vector<int> A;
vector<int> B;
vector<int> C;
vector<int> D;
vector<int> E;
vector<int> F;
vector<LL> xs;
vector<LL> ys;
int st[6001][6001];
bool isInf=false;
LL ret=0;
void f(int p, int q)
{
	if(st[p][q]&16)
	{
		return;
	}
	st[p][q]|=16;
	//cerr << p << ", " << q << endl;
	if(p==0||q==0||p==xs.size()||q==ys.size())
	{
		isInf=true;
		return 0;
	}
  	ret+=(xs[p]-xs[p-1])*(ys[q]-ys[q-1]);
	
	if(!(st[p][q]&1))
	{
		ret+=f(p,q+1);
	}
	if(!(st[p][q]&2))
	{
		ret+=f(p+1,q);
	}
	if(!(st[p][q]&4))
	{
		ret+=f(p,q-1);
	}
	if(!(st[p][q]&8))
	{
		ret+=f(p-1,q);
	}
}
int main(){
	int N,M;
	cin >> N >> M;
	for(int i=0;i<N;i++){
		int a,b,c;
		cin >> a >> b >> c;
		A.push_back(a);
		B.push_back(b);
		C.push_back(c);
		xs.push_back(a);
		xs.push_back(b);
		ys.push_back(c);
	}
	for(int i=0;i<M;i++){
		int a,b,c;
		cin >> a >> b >> c;
		D.push_back(a);
		E.push_back(b);
		F.push_back(c);
		xs.push_back(a);
		ys.push_back(b);
		ys.push_back(c);
	}
	sort(xs.begin(),xs.end());
	xs.resize(unique(xs.begin(),xs.end())-xs.begin());
	sort(ys.begin(),ys.end());
	ys.resize(unique(ys.begin(),ys.end())-ys.begin());
	for(int i=0;i<N;i++){
		int q=lower_bound(ys.begin(),ys.end(),C[i])-ys.begin();
		int p=lower_bound(xs.begin(),xs.end(),min(A[i],B[i]))-xs.begin();
		while(xs[p]<max(A[i],B[i])){
			st[p+1][q]|=1;
			st[p+1][q+1]|=4;
			p++;
		}
	}
	for(int i=0;i<M;i++){
		int q=lower_bound(ys.begin(),ys.end(),min(E[i],F[i]))-ys.begin();
		int p=lower_bound(xs.begin(),xs.end(),D[i])-xs.begin();
		while(ys[q]<max(E[i],F[i])){
			st[p][q+1]|=2;
			st[p+1][q+1]|=8;
			q++;
		}
	}

	int u=lower_bound(xs.begin(),xs.end(),0)-xs.begin();
	int v=lower_bound(ys.begin(),ys.end(),0)-ys.begin();
	f(u,v);
	if(isInf)
	{
		cout << "INF" << endl;
		return 0;
	}
	cout << ret << endl;




    return 0;
}
