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

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


@njit
def arrange_input(abcdef):
    ver_lines = List()
    hor_lines = List()
    x_list = set()
    y_list = set()
    n3 = n * 3
    for a, b, c in zip(abcdef[0:n3:3], abcdef[1:n3:3], abcdef[2:n3:3]):
        y_list.add(a)
        y_list.add(b)
        x_list.add(c)
        ver_lines.append((a, b, c))

    for d, e, f in zip(abcdef[n3 + 0::3], abcdef[n3 + 1::3], abcdef[n3 + 2::3]):
        y_list.add(d)
        x_list.add(e)
        x_list.add(f)
        hor_lines.append((d, e, f))
    x_list.add(0)
    y_list.add(0)

    x_list = np.array(sorted(x_list), dtype=np.int64)
    y_list = np.array(sorted(y_list), dtype=np.int64)

    return ver_lines, hor_lines, x_list, y_list


@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


abcdef = np.array(abcdef, dtype=np.int64)
ver_lines, hor_lines, x_list, y_list = arrange_input(abcdef)
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_down = np.zeros(total, dtype=np.int16)
banned_left = np.zeros(total, dtype=np.int16)
banned_right = np.zeros(total, dtype=np.int16)


@njit
def register_ver_lines(a, b, c, banned_left, banned_right, x_dict, y_dict):
    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
    banned_right[ai + j - 1] += 1
    banned_right[bi + j - 1] -= 1


@njit
def register_hor_lines(d, e, f, banned_up, banned_down, x_dict, y_dict):
    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
    banned_down[ri - row + ej] += 1
    banned_down[ri - row + fj] -= 1


@njit
def accumulate_banned(banned_up, banned_down, banned_left, banned_right):
    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_down[ri1 + j] += banned_down[ri1 + j - 1]
            banned_left[ri1 + j] += banned_left[ri0 + j]
            banned_right[ri1 + j] += banned_right[ri0 + j]


@njit
def dfs(x_list, y_list, x_dict, y_dict, banned_up, banned_down, banned_left, banned_right):
    s = row * y_dict[0] + x_dict[0]
    enable = [-1] * row + ([-1] + [0] * (row - 2) + [-1]) * (col - 2) + [-1] * row

    q = [s]
    moves = [(-row, banned_up), (-1, banned_left), (1, banned_right), (row, banned_down)]
    while q:
        c = q.pop()
        if enable[c] == 1:
            continue
        elif enable[c] == -1:
            return -1
        enable[c] = 1
        for dc, banned in moves:
            if banned[c]:
                continue
            nc = c + dc
            if enable[nc] == 1:
                continue
            q.append(nc)

    ans = 0
    for i in range(col):
        ri = i * row
        for j in range(row):
            if enable[ri + j] != 1:
                continue
            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 ver_lines:
    register_ver_lines(a, b, c, banned_left, banned_right, x_dict, y_dict)
for d, e, f in hor_lines:
    register_hor_lines(d, e, f, banned_up, banned_down, x_dict, y_dict)

accumulate_banned(banned_up, banned_down, banned_left, banned_right)

ans = dfs(x_list, y_list, x_dict, y_dict, banned_up, banned_down, banned_left, banned_right)
print(ans if ans != -1 else 'INF')
