import sys

max_int = 1000000001  # 10^9+1
min_int = -max_int

n, m = map(int, sys.stdin.readline().split())

x_coords = set()
y_coords = set()

hor = {}  # [x => [[a,b], [a,b]], ...]
ver = {}

for _n in range(n):
    a, b, c = map(int, sys.stdin.readline().split())
    x_coords.add(a)
    x_coords.add(b)
    y_coords.add(c)
    if c not in ver:
        ver[c] = [[a, b]]
    else:
        ver[c].append([a, b])

for _m in range(m):
    d, e, f = map(int, sys.stdin.readline().split())
    x_coords.add(d)
    y_coords.add(e)
    y_coords.add(f)
    if d not in hor:
        hor[d] = [[e, f]]
    else:
        hor[d].append([e, f])

x_coords = list(x_coords)
x_coords.sort()

y_coords = list(y_coords)
y_coords.sort()

x_indices = {}
y_indices = {}

x0 = 0
index = 0
for coord in x_coords:
    x_indices[coord] = index
    if coord <= 0:
        x0 = index
    index += 1

y0 = 0
index = 0
for coord in y_coords:
    y_indices[coord] = index
    if coord <= 0:
        y0 = index
    index += 1

if x0 == len(x_coords) - 1 or y0 == len(y_coords) - 1:
    print('INF')
    exit()

hor_borders = set()
ver_borders = set()

for x_coord in hor:
    x = x_indices[x_coord]
    for y1_coord, y2_coord in hor[x_coord]:
        y1 = y_indices[y1_coord]
        y2 = y_indices[y2_coord]
        for i in range(y1, y2):
            hor_borders.add((x, i))

for y_coord in ver:
    y = y_indices[y_coord]
    for x1_coord, x2_coord in ver[y_coord]:
        x1 = x_indices[x1_coord]
        x2 = x_indices[x2_coord]
        for i in range(x1, x2):
            ver_borders.add((i, y))

# print(hor_borders, ver_borders)
# exit()

# exit()
contenders = [(x0, y0)]
visited = set()
while contenders:
    new_contenders = []
    for x, y in contenders:
        if (x, y) in visited:
            continue
        # print(x, y)
        visited.add((x, y))
        if x < 0 or y < 0 or x == len(x_coords) or y == len(y_coords):
            print('INF')
            exit()

        # вверх
        if (x, y) not in hor_borders:
            # print('up to ', x - 1, y)
            new_contenders.append((x - 1, y))

        # влево
        if (x, y) not in ver_borders:
            # print('left to ', x, y - 1)
            new_contenders.append((x, y - 1))

        # вниз
        if (x + 1, y) not in hor_borders:
            # print('down to ', x + 1, y)
            new_contenders.append((x + 1, y))

        # вправо
        if (x, y + 1) not in ver_borders:
            # print('right to ')
            new_contenders.append((x, y + 1))
    contenders = new_contenders

    # print(new_contenders, ans)
    # break

area = 0
for x, y in visited:
    area += (x_coords[x + 1] - x_coords[x]) * (y_coords[y + 1] - y_coords[y])

print(area)