### BUGGY CODE ###

import sys
import numpy as np


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.zeros((nrows, ncols), dtype=type)
	for i in range(nrows):
		data[i, :] = input_row(ncols, type, **kwargs)
	return data

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_closed = set()
y_closed = set()
for i in range(N):
	c = bisect_right(xs, C[i])
	a = bisect_right(ys, A[i])
	b = bisect_right(ys, B[i])
	for y in range(a, b):
		x_closed.add(((c-1, c), y))

for i in range(M):
	d = bisect_right(ys, D[i])
	e = bisect_right(xs, E[i])
	f = bisect_right(xs, F[i])
	for x in range(e, f):
		y_closed.add((x, (d-1, d)))

nexts = [(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.pop()
	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 ((xi-1, xi), yi) not in x_closed:
				nexts.append((xi-1, yi))
			if ((xi, xi+1), yi) not in x_closed:
				nexts.append((xi+1, yi))
			if (xi, (yi-1, yi)) not in y_closed:
				nexts.append((xi, yi-1))
			if (xi, (yi, yi+1)) not in y_closed:
				nexts.append((xi, yi+1))
		else:
			area = 'INF'
			break

print(area)



### FIXED CODE ###

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)