import sys
import numpy as np
from numba import njit, types
from numba.typed import Dict

n, m, *abcdef = map(int, sys.stdin.buffer.read().split())

n3 = n * 3
aaa = abcdef[0:n3:3]
bbb = abcdef[1:n3:3]
ccc = abcdef[2:n3:3]
ddd = abcdef[n3 + 0::3]
eee = abcdef[n3 + 1::3]
fff = abcdef[n3 + 2::3]
x_list = {0}
x_list.update(ccc)
x_list.update(eee)
x_list.update(fff)
y_list = {0}
y_list.update(aaa)
y_list.update(bbb)
y_list.update(ddd)


@njit
def create_dict(x_list):
    d = Dict.empty(key_type=types.int64, value_type=types.int64)
    for i in range(len(x_list)):
        d[x_list[i]] = i + 1
    return d


x_list = np.array(sorted(x_list), dtype=np.int64)
y_list = np.array(sorted(y_list), dtype=np.int64)
x_dict = create_dict(x_list)
y_dict = create_dict(y_list)
row_real = len(x_list)
col_real = len(y_list)
row = row_real + 2
col = col_real + 2
total = row * col

banned_up = np.zeros(total, dtype=np.int16)
banned_left = np.zeros(total, dtype=np.int16)


@njit
def register_ver_lines(a, b, c, banned_left, x_dict, y_dict, row):
    if a > b:
        a, b = b, a
    ai = y_dict[a] * row
    bi = y_dict[b] * row
    j = x_dict[c]
    banned_left[ai + j] += 1
    banned_left[bi + j] -= 1


@njit
def register_hor_lines(d, e, f, banned_up, x_dict, y_dict, row):
    if e > f:
        e, f = f, e
    ri = y_dict[d] * row
    ej = x_dict[e]
    fj = x_dict[f]
    banned_up[ri + ej] += 1
    banned_up[ri + fj] -= 1


@njit
def accumulate_banned(banned_up, banned_left, row, col):
    for i in range(1, col):
        ri0 = row * (i - 1)
        ri1 = row * i
        for j in range(1, row):
            banned_up[ri1 + j] += banned_up[ri1 + j - 1]
            banned_left[ri1 + j] += banned_left[ri0 + j]


@njit
def solve(x_list, y_list, x_dict, y_dict, banned_up, banned_left, row, col):
    s = row * y_dict[0] + x_dict[0]
    enable = np.array([-1] * row + ([-1] + [0] * (row - 2) + [-1]) * (col - 2) + [-1] * row, dtype=np.int8)
    enable[s] = 1
    q = [s]

    def check(nc):
        nonlocal enable, q
        if not enable[nc] == 1:
            q.append(nc)
            enable[nc] = 1

    ans = 0
    while q:
        c = q.pop()

        if not banned_up[c]:
            nc = c - row
            if enable[nc] == -1:
                return -1
            check(nc)

        if not banned_left[c]:
            nc = c - 1
            if enable[nc] == -1:
                return -1
            check(nc)

        nc = c + 1
        if not banned_left[nc]:
            if enable[nc] == -1:
                return -1
            check(nc)

        nc = c + row
        if not banned_up[nc]:
            if enable[nc] == -1:
                return -1
            check(nc)

        i, j = divmod(c, row)
        t = y_list[i - 1]
        b = y_list[i]
        l = x_list[j - 1]
        r = x_list[j]
        ans += (b - t) * (r - l)

    return ans


for a, b, c in zip(aaa, bbb, ccc):
    register_ver_lines(a, b, c, banned_left, x_dict, y_dict, row)
for d, e, f in zip(ddd, eee, fff):
    register_hor_lines(d, e, f, banned_up, x_dict, y_dict, row)

accumulate_banned(banned_up, banned_left, row, col)

ans = solve(x_list, y_list, x_dict, y_dict, banned_up, banned_left, row, col)
print(ans if ans != -1 else 'INF')


Measured memory_bytes: 302788