#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
int n[2], a, b, c, unzip[2][3005], *e[2], m[2], dp[3005][3005], dx[] = {1,-1,0,0}, dy[] = {0, 0,1,-1};
ll ans;
bool out[2][3005][3005], used[3005][3005];
tuple<int,int,int> forb[2][1005];
map<int, int> zip[2];
stack<pair<int,int>> st;
int main(){
	scanf("%d%d", n, n+1);
	e[0] = unzip[0]+1; e[1] = unzip[1]+1;
	rep(t,2) rep(i,n[t]){
		scanf("%d%d%d", &a, &b, &c);
		forb[t][i] = {a, (t?b:c), (t?c:b)};
		*e[0]++ = a;
		*e[t]++ = b;
		*e[1]++ = c;
	}
	rep(t,2){
		sort(unzip[t],e[t]);
		e[t] = unique(unzip[t], e[t]);
		m[t] = e[t] - unzip[t];
		if(unzip[t][m[t]-1] == 0) return 0 * puts("INF");
		rep(i,m[t]) zip[t][unzip[t][i]] = i;
	}
	rep(t,2) rep(i,n[t]){
		auto [a, b, c] = forb[t][i];
		a = zip[0][a]; b = zip[1][b]; c = zip[t][c];
		if(t) for(; b < c; b++) out[!t][a][b] = true;
		else for(; a < c; a++) out[!t][a][b] = true;
	}
	st.emplace(zip[0][0],zip[1][0]); used[zip[0][0]][zip[1][0]] = true;
	while(!st.empty()){
		auto [x, y] = st.top(); st.pop();
		ans += (ll)(unzip[0][x+1] - unzip[0][x]) * (unzip[1][y+1] - unzip[1][y]);
		rep(t,4){
			int nx = x + dx[t], ny = y + dy[t];
			if(t%2 == 0 && out[t/2][nx][ny]) continue;
			if(t%2 == 1 && out[t/2][x][y]) continue;
			if(used[nx][ny]) continue;
			if(nx < 0 || m[0] <= nx || ny < 0 || m[1] <= ny) return 0 * puts("INF");
			used[nx][ny] = true;
			st.emplace(nx,ny);
		}
	}
	printf("%lld\n", ans);
}