import sys
from bisect import bisect_left, bisect_right


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

def input_2d_T(nrows : int, ncols : int, type=int, **kwargs):
	data = [[None] * nrows for _ in range(ncols)]
	for i in range(nrows):
		for j, v in enumerate(inputs(type)):
			data[j][i] = v
	return data

from collections import deque

N, M = inputs(int)
A, B, C = input_2d_T(N, 3)
D, E, F = input_2d_T(M, 3)
xs = sorted(set(C))
ys = sorted(set(D))

x_guard = [[False for _ in range(len(ys)+1)] for _ in range(len(xs)+1)]
y_guard = [[False for _ in range(len(ys)+1)] for _ in range(len(xs)+1)]

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

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

cow = (
	bisect_right(xs, 0),
	bisect_right(ys, 0)
)
nexts = deque([cow])
visited = [[0 for _ in range(len(ys)+1)] for _ in range(len(xs)+1)]
visited[cow[0]][cow[1]] = True

area = 0

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

print(area)

