#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
const int MAXN = 1e3 + 5;
const int MAXM = 1e3 + 5;
const int MAXD = MAXN*3 + MAXM*3;

struct DSC
{
	int dsc[MAXD], cnt;
	DSC(void){ cnt=0;}
	inline int& operator [] (const int &x){ return dsc[x];}
	inline void insert(const int &x){ dsc[++cnt] = x;}
	inline void solve(void){ sort(dsc+1,dsc+cnt+1); cnt = unique(dsc+1,dsc+cnt+1)-dsc-1;}
	inline void find(int &x){ x = lower_bound(dsc+1,dsc+cnt+1, x) - dsc;}
}dsc;

struct Line
{
	int a,b,c;
}p[MAXN], q[MAXM];

struct Node
{
	int x,y;
};

bool rig[MAXD][MAXD], dwn[MAXD][MAXD];

queue<Node> que;
bool vis[MAXD][MAXD];
inline void push(int x,int y)
{
	if(x<=1 || y<=1 || x>dsc.cnt || y>dsc.cnt)
		printf("INF"), exit(0);
	if(vis[x][y]) return;
	vis[x][y] = 1;
	que.push((Node){x,y});
}

inline ll bfs(int sx,int sy)
{
	ll res=0;
	push(sx,sy);
	while(!que.empty())
	{
		int x=que.front().x, y=que.front().y;
		que.pop();
		res += (ll)(dsc[x]-dsc[x-1]) * (dsc[y]-dsc[y-1]);
		
		if(!dwn[x][y]) push(x+1,y);
		if(!rig[x][y]) push(x,y+1);
		if(!dwn[x-1][y]) push(x-1,y);
		if(!rig[x][y-1]) push(x,y-1);
	}
	return res;
}

int main(void)
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1; i<=n; ++i)
		scanf("%d%d%d",&p[i].a,&p[i].b,&p[i].c);
	for(int i=1; i<=m; ++i)
		scanf("%d%d%d",&q[i].a,&q[i].b,&q[i].c);
	
	int sx=0, sy=0;
	dsc.insert(0);
	for(int i=1; i<=n; ++i)
		dsc.insert(p[i].a), dsc.insert(p[i].b), dsc.insert(p[i].c);
	for(int i=1; i<=m; ++i)
		dsc.insert(q[i].a), dsc.insert(q[i].b), dsc.insert(q[i].c);
	dsc.solve();
	dsc.find(sx); dsc.find(sy);
	for(int i=1; i<=n; ++i)
		dsc.find(p[i].a), dsc.find(p[i].b), dsc.find(p[i].c);
	for(int i=1; i<=m; ++i)
		dsc.find(q[i].a), dsc.find(q[i].b), dsc.find(q[i].c);
	
	for(int i=1; i<=n; ++i)
	{
		int a=p[i].a, b=p[i].b, c=p[i].c;
		
		for(int j=a+1; j<=b; ++j)
			rig[j][c] = 1;
	}
	for(int i=1; i<=m; ++i)
	{
		int a=q[i].a, b=q[i].b, c=q[i].c;
		
		for(int j=b+1; j<=c; ++j)
			dwn[a][j] = 1;
	}
	
	printf("%lld",bfs(sx,sy));
	return 0;
}