#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;

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

int N, M, A[1010], B[1010], C[1010], D[1010], E[1010], F[1010];
int XC, X[3030], YC, Y[3030]; int Z[3030][3030]; bool K[3030][3030];

int getx(int x) { return lower_bound(X, X + XC, x) - X; }
int gety(int y) { return lower_bound(Y, Y + YC, y) - Y; }

queue<pair<int, int> > Q;
void enq(int x, int y)
{
	if (!K[x][y]){
		Q.push({ x,y }); K[x][y] = 1;
	}
}

int main()
{
	scanf ("%d %d", &N, &M);
	for (int i = 0; i < N; i++){
		scanf ("%d %d %d", &A[i], &B[i], &C[i]);
		X[XC++] = A[i];
		X[XC++] = B[i];
		Y[YC++] = C[i];
	}
	for (int i = 0; i < M; i++){
		scanf ("%d %d %d", &D[i], &E[i], &F[i]);
		X[XC++] = D[i];
		Y[YC++] = E[i];
		Y[YC++] = F[i];
	}
	X[XC++] = -1.1e9;
	X[XC++] = 0;
	X[XC++] = 1.1e9;
	Y[YC++] = -1.1e9;
	Y[YC++] = 0;
	Y[YC++] = 1.1e9;

	sort(X, X + XC);
	XC = unique(X, X + XC) - X - 1;
	sort(Y, Y + YC);
	YC = unique(Y, Y + YC) - Y - 1;

	for (int i = 0; i < N; i++){
		int a = getx(A[i]);
		int b = getx(B[i]);
		int c = gety(C[i]);

		for (int j = a; j < b; j++){
			Z[j][c - 1] |= (1 << 0);
			Z[j][c] |= (1 << 2);
		}
	}

	for (int i = 0; i < M; i++){
		int d = getx(D[i]);
		int e = gety(E[i]);
		int f = gety(F[i]);

		for (int j = e; j < f; j++){
			Z[d - 1][j] |= (1 << 1);
			Z[d][j] |= (1 << 3);
		}
	}

	int sx = getx(0), sy = gety(0);
	for (int p=0;p<2;p++) for (int q=0;q<2;q++) enq(sx - p, sy - q);
	while (!Q.empty()){
		int x = Q.front().first, y = Q.front().second; Q.pop();
		for (int k = 0; k < 4; k++) if (~Z[x][y] & (1 << k)){
			int px = x + dx[k];
			int py = y + dy[k];
			if (px < 0 || px >= XC || py < 0 || py >= YC) continue;
			enq(px, py);
		}
	}

	for (int i = 0; i < YC; i++){
		if (K[0][i] || K[XC - 1][i]){
			puts("INF");
			return 0;
		}
	}
	for (int i = 0; i < XC; i++){
		if (K[i][0] || K[i][YC - 1]){
			puts("INF");
			return 0;
		}
	}
	long long ans = 0;
	for (int i = 0; i < XC; i++) for (int j = 0; j < YC; j++) if (K[i][j]){
		ans += 1ll * (X[i + 1] - X[i]) * (Y[j + 1] - Y[j]);
	}
	printf ("%lld\n", ans);
	return 0;
}