#!/usr/bin/env python3
import sys
input = sys.stdin.readline
from collections import deque
INF = 10**20 

n, m = map(int, input().split())
xseen = set()
xseen.add(INF); xseen.add(-INF)
yseen = set()
yseen.add(INF); yseen.add(-INF)
a_b_c = []
for _ in range(n):
    a, b, c = map(int, input().split())
    xseen.add(a)
    xseen.add(b)
    yseen.add(c)
    a_b_c.append((a, b, c))
d_e_f = []
for _ in range(m):
    d, e, f = map(int, input().split())
    xseen.add(d)
    yseen.add(e)
    yseen.add(f)
    d_e_f.append((d, e, f))

xlen = len(xseen) * 2 - 1
ylen = len(yseen) * 2 - 1

xseen = sorted(list(xseen))
xcomp = {val:i for i, val in enumerate(xseen)}
yseen = sorted(list(yseen))
ycomp = {val:i for i, val in enumerate(yseen)}

field = [[False] * ylen for _ in range(xlen)]
x_range = [0] * xlen
y_range = [0] * ylen
x_range[0] = x_range[-1] = INF
y_range[0] = y_range[-1] = INF
for i, (x1, x2) in enumerate(zip(xseen, xseen[1:])):
    x_range[i * 2 + 1] = x2 - x1
    if x1 <= 0 <= x2:
        sx = i * 2 + 1
for i, (y1, y2) in enumerate(zip(yseen, yseen[1:])):
    y_range[i * 2 + 1] = y2 - y1
    if y1 <= 0 <= y2:
        sy = i * 2 + 1
# print(sx, sy)

for a, b, c in a_b_c:
    y = ycomp[c] * 2
    for x in range(xcomp[a] * 2, xcomp[b] * 2 + 1):
        field[x][y] = True 

for d, e, f in d_e_f:
    x = xcomp[d] * 2
    for y in range(ycomp[e] * 2, ycomp[f] * 2 + 1):
        field[x][y] = True 

# for line in field:
#     print("".join([item for item in line]))

diff = ((0, 1), (1, 0), (-1, 0), (0, -1))
ans = 0

dq = deque([(sx, sy)])
field[sx][sy] = True 
ans += x_range[sx] * y_range[sy]
while dq:
    x, y = dq.popleft()
    for dx, dy in diff:
        nx, ny = dx + x, dy + y
        if field[nx][ny]:
            continue
        nx += dx; ny += dy
        if field[nx][ny]:
            continue
        field[nx][ny] = True 
        dq.append((nx, ny))
        ans += x_range[nx] * y_range[ny] 
        if ans >= INF:
            print("INF")
            exit()

print(ans)