#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
const int INF=500+5;
const int N=4000+5;
const ll oo=1e18+5;
const ll mod=998244353;

int n,m;
vector<int> xs,ys;
int ban[N][N][4];
int used[N][N];
int a[N],b[N],c[N],d[N],e[N],f[N];

int dx[4] = {-1,0,0,1};
int dy[4] = {0,1,-1,0};

void bfs(int x,int y){
	queue<pair<int,int>> Q;
	Q.push({x,y});
	used[x][y]=1;
	while(!Q.empty()){
		int u=Q.front().first;
		int v=Q.front().second;
		Q.pop();
		for(int dir=0;dir<4;++dir){
			if(ban[u][v][dir]) continue;
			int new_u=u+dx[dir];
			int new_v=v+dy[dir];
			if(new_u>=0&&new_u<=(int)xs.size()&&new_v>=0&&new_v<=(int)ys.size()){
				if(!used[new_u][new_v]){
					used[new_u][new_v]=1;
					Q.push({new_u,new_v});
				}
			}
		}
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;++i){
		cin>>a[i]>>b[i]>>c[i];
		xs.push_back(a[i]);
		xs.push_back(b[i]);
		ys.push_back(c[i]);
	}
	for(int i=1;i<=m;++i){
		cin>>d[i]>>e[i]>>f[i];
		xs.push_back(d[i]);
		ys.push_back(e[i]);
		ys.push_back(f[i]);
	}
	sort(all(xs));
	sort(all(ys));
	xs.resize(unique(all(xs))-xs.begin());
	ys.resize(unique(all(ys))-ys.begin());
	for(int i=1;i<=n;++i){
		int id_a=lower_bound(all(xs),a[i])-xs.begin();
		int id_b=lower_bound(all(xs),b[i])-xs.begin();
		int id_c=lower_bound(all(ys),c[i])-ys.begin();
		for(int j=id_a+1;j<=id_b;++j) ban[j][id_c][1]=1,ban[j][id_c+1][2]=1;
	}
	for(int i=1;i<=m;++i){
		int id_d=lower_bound(all(xs),d[i])-xs.begin();
		int id_e=lower_bound(all(ys),e[i])-ys.begin();
		int id_f=lower_bound(all(ys),f[i])-ys.begin();
		for(int j=id_e+1;j<=id_f;++j) ban[id_d][j][3]=1,ban[id_d+1][j][0]=1;
	}
	int x=lower_bound(all(xs),0)-xs.begin();
	int y=lower_bound(all(ys),0)-ys.begin();
	bfs(x,y);
	for(int i=0;i<=(int)xs.size();++i){
		if(used[i][0]||used[i][(int)ys.size()]){
			return cout<<"INF",0;
		}
	}
	for(int i=0;i<=(int)ys.size();++i){
		if(used[0][i]||used[(int)xs.size()][i]){
			return cout<<"INF",0;
		}
	}
	ll ans=0;
	for(int i=1;i<(int)xs.size();++i){
		for(int j=1;j<(int)ys.size();++j){
			if(used[i][j]) ans+=1ll*(xs[i]-xs[i-1])*(ys[j]-ys[j-1]);
		}
	}
	cout<<ans;
	return 0;
}
