import sys
import numpy as np
from itertools import chain


def inputs(func=lambda x: x, sep=None, maxsplit=-1):
	return map(func, sys.stdin.readline().split(sep=sep, maxsplit=maxsplit))

def input_row(n : int, type=np.int, **kwargs):
	return np.fromiter(inputs(type, **kwargs), dtype=type)

def input_2d(nrows : int, ncols : int, type=np.int, **kwargs):
	data = np.fromiter(
		chain.from_iterable(
			inputs(type) for _ in range(nrows)
		),
		dtype=type
	)
	for i in range(nrows):
		data[i, :] = input_row(ncols, type, **kwargs)
	return data

from collections import deque
from bisect import bisect_right
import numpy as np


N, M = inputs(int)
A, B, C = input_2d(N, 3).T
D, E, F = input_2d(M, 3).T
xs = set()
ys = set()

for i in range(N):
	xs.add(C[i])
	ys.add(A[i])
	ys.add(B[i])

for i in range(M):
	ys.add(D[i])
	xs.add(E[i])
	xs.add(F[i])

xs = sorted(xs)
ys = sorted(ys)

x_guard = np.zeros((len(xs)+1, len(ys)+1), dtype=bool)
y_guard = np.zeros((len(xs)+1, len(ys)+1), dtype=bool)

for i in range(N):
	c = bisect_right(xs, C[i])
	a = bisect_right(ys, A[i])
	b = bisect_right(ys, B[i])
	x_guard[c, a:b] = True

for i in range(M):
	d = bisect_right(ys, D[i])
	e = bisect_right(xs, E[i])
	f = bisect_right(xs, F[i])
	y_guard[e:f, d] = True

nexts = deque()
nexts.append((bisect_right(xs, 0), bisect_right(ys, 0)))
visited = np.zeros((len(xs)+1, len(ys)+1), dtype=bool)

area = 0

while nexts:
	xi, yi = nexts.popleft()
	if not visited[xi, yi]:
		visited[xi, yi] = True
		if 0 < xi < len(xs) and 0 < yi < len(ys):
			area += (xs[xi] - xs[xi-1]) * (ys[yi] - ys[yi-1])
			if not x_guard[xi, yi]:
				nexts.append((xi-1, yi))
			if not x_guard[xi+1, yi]:
				nexts.append((xi+1, yi))
			if not y_guard[xi, yi]:
				nexts.append((xi, yi-1))
			if not y_guard[xi, yi+1]:
				nexts.append((xi, yi+1))
		else:
			area = 'INF'
			break

print(area)

