def numba_compile(numba_config):
    import os, sys
    if sys.argv[-1] == "ONLINE_JUDGE":
        from numba import njit
        from numba.pycc import CC
        cc = CC("my_module")
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature)(func)
            cc.export(func.__name__, signature)(func)
        cc.compile()
        exit()
    elif os.name == "posix":
        exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
        for func, _ in numba_config:
            globals()[func.__name__] = vars()[func.__name__]
    else:
        from numba import njit
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature, cache=True)(func)
        print("compiled!", file=sys.stderr)

import sys
import numpy as np

def solve(N, M, ABCDEF):
    L, R, U, D = 0, 1, 2, 3
    Dy = [0, 0, -1, 1]
    Dx = [-1, 1, 0, 0]
    mapping_inv_x = [0]
    mapping_inv_y = [0]
    for i in range(N):
        y1, y2, x = ABCDEF[i]
        mapping_inv_x.append(x)
        mapping_inv_y.append(y1)
        mapping_inv_y.append(y2)
    for i in range(N, N+M):
        y, x1, x2 = ABCDEF[i]
        mapping_inv_x.append(x1)
        mapping_inv_x.append(x2)
        mapping_inv_y.append(y)
    mapping_inv_y = sorted(set(mapping_inv_y))
    mapping_inv_x = sorted(set(mapping_inv_x))
    H = len(mapping_inv_y) + 1
    W = len(mapping_inv_x) + 1
    E = np.ones((H, W, 4), dtype=np.int8)
    #mapping_y = {v: i for i, v in enumerate(mapping_inv_y, 1)}
    #mapping_x = {v: i for i, v in enumerate(mapping_inv_x, 1)}
    mapping_y = {}
    for i, v in enumerate(mapping_inv_y, 1):
        mapping_y[v] = i
    mapping_x = {}
    for i, v in enumerate(mapping_inv_x, 1):
        mapping_x[v] = i
    for i in range(N):
        y1, y2, x = ABCDEF[i]
        y1 = mapping_y[y1]
        y2 = mapping_y[y2]
        x = mapping_x[x]
        for y in range(y1, y2):
            E[y, x, L] = 0
            E[y, x-1, R] = 0
    for i in range(N, N+M):
        y, x1, x2 = ABCDEF[i]
        y = mapping_y[y]
        x1 = mapping_x[x1]
        x2 = mapping_x[x2]
        for x in range(x1, x2):
            E[y, x, U] = 0
            E[y-1, x, D] = 0
    Diff_x = np.diff(np.array(mapping_inv_x))
    Diff_y = np.diff(np.array(mapping_inv_y))
    Area = np.empty((H, W), dtype=np.int64)
    Area[1:-1, 1:-1] = Diff_y.reshape(-1, 1) * Diff_x
    Closed = np.zeros((H, W), dtype=np.int8)
    y, x = mapping_y[0], mapping_x[0]
    Closed[y, x] = 1
    ans = 0
    stack = [(y, x)]
    while stack:
        vy, vx = stack.pop()
        if vy==0 or vy==H-1 or vx==0 or vx==W-1:
            print("INF")
            return
        ans += Area[vy, vx]
        for direction in [L, R, U, D]:
            if E[vy, vx, direction]:
                uy, ux = vy + Dy[direction], vx + Dx[direction]
                if not Closed[uy, ux]:
                    stack.append((uy, ux))
                    Closed[uy, ux] = 1
    print(ans)

numba_compile([
    [solve, "(i8,i8,i8[:,:])"],
])

def main():
    N, M = map(int, sys.stdin.buffer.readline().split())
    ABCDEF = np.array(sys.stdin.buffer.read().split(), dtype=np.int64).reshape(-1, 3)
    solve(N, M, ABCDEF)

main()


Measured memory_bytes: 204100