#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int INF = 0x3f3f3f3f;
const int N = 3e3 + 10;
int n, m;
int A[N], B[N], C[N], D[N], E[N], F[N];
ll ans;
vector<int>xx, yy;
int id(vector<int>&vc, int x) {
	return lower_bound(vc.begin(), vc.end(), x) - vc.begin();
}
int dx[]{ 0,0,-1,1 };
int dy[]{ -1,1,0,0 };
int die[N][N][4];
typedef pair<int, int> pii;
queue<pii>q;
int vis[N][N];
int main() {
	scanf("%d%d", &n, &m);
	xx.push_back(0);
	yy.push_back(0);
	xx.push_back(-INF); xx.push_back(INF);
	yy.push_back(-INF); yy.push_back(INF);
	for (int i = 1; i <= n; i++) {
		scanf("%d%d%d", &A[i], &B[i], &C[i]);
		xx.push_back(A[i]);
		xx.push_back(B[i]);
		yy.push_back(C[i]);
	}
	for (int i = 1; i <= m; i++) {
		scanf("%d%d%d", &D[i], &E[i], &F[i]);
		yy.push_back(E[i]);
		yy.push_back(F[i]);
		xx.push_back(D[i]);
	}
	sort(xx.begin(), xx.end()); xx.erase(unique(xx.begin(), xx.end()), xx.end());
	sort(yy.begin(), yy.end()); yy.erase(unique(yy.begin(), yy.end()), yy.end());
	for (int i = 1; i <= n; i++) {
		A[i] = id(xx, A[i]);
		B[i] = id(xx, B[i]);
		C[i] = id(yy, C[i]);
		for (int j = A[i]; j < B[i]; j++) {
			die[j][C[i]][0] = 1;
			die[j][C[i] - 1][1] = 1;
		}
	}
	for (int i = 1; i <= m; i++) {
		D[i] = id(xx, D[i]);
		E[i] = id(yy, E[i]);
		F[i] = id(yy, F[i]);
		for (int j = E[i]; j < F[i]; j++) {
			die[D[i]][j][2] = 1;
			die[D[i] - 1][j][3] = 1;
		}
	}
	q.push(pii(id(xx, 0), id(yy, 0)));
	while (!q.empty()) {
		int x = q.front().first, y = q.front().second; q.pop();
		if (vis[x][y])continue;
		if (x == 0 || x == (int)xx.size() - 1 || y == 0 || y == (int)yy.size() - 1) {
			puts("INF");
			return 0;
		}
		ans += 1ll * (xx[x + 1] - xx[x])*(yy[y + 1] - yy[y]);
		vis[x][y] = 1;
		for (int i = 0; i < 4; i++) {
			if (die[x][y][i])continue;
			int nx = x + dx[i], ny = y + dy[i];
			q.push(pii(nx, ny));
		}
	}
	printf("%lld\n", ans);
	return 0;
}
