import sys

import numpy as np

from numba import njit



read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



INF = 10**9 + 1



def precompute(N, M, data):

    data = data.reshape(-1, 3)

    A, B, C = data[:N].T

    D, E, F = data[N:].T

    X = np.unique(np.concatenate([A, B, D, [0, -INF, INF]]))

    Y = np.unique(np.concatenate([C, E, F, [0, -INF, INF]]))

    A = np.searchsorted(X, A)

    B = np.searchsorted(X, B)

    D = np.searchsorted(X, D)

    C = np.searchsorted(Y, C)

    E = np.searchsorted(Y, E)

    F = np.searchsorted(Y, F)

    return A, B, C, D, E, F, X, Y



def solve(A, B, C, D, E, F, X, Y):

    H, W = len(X), len(Y)

    N = H * W

    DX = X[1:] - X[:-1]

    DY = Y[1:] - Y[:-1]



    def set_ng(A, B, C, D, E, F, H, W):

        ng = np.zeros((H * W, 4), np.bool_)



        for i in range(len(A)):

            for x in range(A[i], B[i]):

                v = x * W + C[i]

                ng[v][1] = 1

                ng[v - 1][0] = 1



        for i in range(len(D)):

            for y in range(E[i], F[i]):

                v = D[i] * W + y

                ng[v][3] = 1

                ng[v - W][2] = 1

        return ng



    ng = set_ng(A, B, C, D, E, F, H, W)

    x0, y0 = np.searchsorted(X, 0), np.searchsorted(Y, 0)

    v0 = x0 * W + y0

    visited = np.zeros(N, np.bool_)

    visited[v0] = 1

    stack = np.empty(N, np.int32)

    p = 0

    ret = 0



    def area(x):

        x, y = divmod(x, W)

        return DX[x] * DY[y]



    def push(x):

        nonlocal p, ret

        stack[p] = x

        visited[x] = 1

        ret += area(x)

        p += 1



    def pop():

        nonlocal p

        p -= 1

        return stack[p]



    push(v0)

    move = (1, -1, W, -W)

    while p:

        v = pop()

        for i in range(4):

            if ng[v][i]:

                continue

            w = v + move[i]

            if visited[w]:

                continue

            x, y = divmod(w, W)

            if x == 0 or x == H - 1 or y == 0 or y == W - 1:

                return 0

            push(w)

    return ret



def cc_export():

    from numba.pycc import CC

    cc = CC('my_module')

    signature = '(i8[:],i8[:],i8[:],i8[:],i8[:],i8[:],i8[:],i8[:])'

    cc.export('solve', signature)(solve)

    cc.compile()



if sys.argv[-1] == 'ONLINE_JUDGE':

    cc_export()

    exit()



from my_module import solve



N, M = list(map(int, readline().split()))

data = np.int64(read().split())



x = solve(*precompute(N, M, data))

if x == 0:

    print('INF')

else:

    print(x)
import sys

import numpy as np



read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



INF = 10**9 + 1



def precompute(N, M, data):

    data = data.reshape(-1, 3)

    A, B, C = data[:N].T

    D, E, F = data[N:].T

    X = np.unique(np.concatenate([A, B, D, [0, -INF, INF]]))

    Y = np.unique(np.concatenate([C, E, F, [0, -INF, INF]]))

    A = np.searchsorted(X, A)

    B = np.searchsorted(X, B)

    D = np.searchsorted(X, D)

    C = np.searchsorted(Y, C)

    E = np.searchsorted(Y, E)

    F = np.searchsorted(Y, F)

    return A, B, C, D, E, F, X, Y



def solve(A, B, C, D, E, F, X, Y):

    H, W = len(X), len(Y)

    N = H * W

    DX = X[1:] - X[:-1]

    DY = Y[1:] - Y[:-1]



    def set_ng(A, B, C, D, E, F, H, W):

        ng = np.zeros((H * W, 4), np.bool_)



        for i in range(len(A)):

            for x in range(A[i], B[i]):

                v = x * W + C[i]

                ng[v][1] = 1

                ng[v - 1][0] = 1



        for i in range(len(D)):

            for y in range(E[i], F[i]):

                v = D[i] * W + y

                ng[v][3] = 1

                ng[v - W][2] = 1

        return ng



    ng = set_ng(A, B, C, D, E, F, H, W)

    x0, y0 = np.searchsorted(X, 0), np.searchsorted(Y, 0)

    v0 = x0 * W + y0

    visited = np.zeros(N, np.bool_)

    visited[v0] = 1

    stack = np.empty(N, np.int32)

    p = 0

    ret = 0



    def area(x):

        x, y = divmod(x, W)

        return DX[x] * DY[y]



    def push(x):

        nonlocal p, ret

        stack[p] = x

        visited[x] = 1

        ret += area(x)

        p += 1



    def pop():

        nonlocal p

        p -= 1

        return stack[p]



    push(v0)

    move = (1, -1, W, -W)

    while p:

        v = pop()

        for i in range(4):

            if ng[v][i]:

                continue

            w = v + move[i]

            if visited[w]:

                continue

            x, y = divmod(w, W)

            if x == 0 or x == H - 1 or y == 0 or y == W - 1:

                return 0

            push(w)

    return ret



def cc_export():

    from numba.pycc import CC

    cc = CC('my_module')

    signature = '(i8[:],i8[:],i8[:],i8[:],i8[:],i8[:],i8[:],i8[:])'

    cc.export('solve', signature)(solve)

    cc.compile()



if sys.argv[-1] == 'ONLINE_JUDGE':

    cc_export()

    exit()



from my_module import solve



N, M = list(map(int, readline().split()))

data = np.int64(read().split())



x = solve(*precompute(N, M, data))

if x == 0:

    print('INF')

else:

    print(x)
import sys
import numpy as np
from numba import njit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
INF = 10**9 + 1


def precompute(N, M, data):
    data = data.reshape(-1, 3)
    A, B, C = data[:N].T
    D, E, F = data[N:].T
    X = np.unique(np.concatenate([A, B, D, [0, -INF, INF]]))
    Y = np.unique(np.concatenate([C, E, F, [0, -INF, INF]]))
    A = np.searchsorted(X, A)
    B = np.searchsorted(X, B)
    D = np.searchsorted(X, D)
    C = np.searchsorted(Y, C)
    E = np.searchsorted(Y, E)
    F = np.searchsorted(Y, F)
    return A, B, C, D, E, F, X, Y


def solve(A, B, C, D, E, F, X, Y):
    H, W = len(X), len(Y)
    N = H * W
    DX = X[1:] - X[:-1]
    DY = Y[1:] - Y[:-1]

    def set_ng(A, B, C, D, E, F, H, W):
        ng = np.zeros((H * W, 4), np.bool_)
        for i in range(len(A)):
            for x in range(A[i], B[i]):
                v = x * W + C[i]
                ng[v][1] = 1
                ng[v - 1][0] = 1
        for i in range(len(D)):
            for y in range(E[i], F[i]):
                v = D[i] * W + y
                ng[v][3] = 1
                ng[v - W][2] = 1
        return ng

    ng = set_ng(A, B, C, D, E, F, H, W)
    x0, y0 = np.searchsorted(X, 0), np.searchsorted(Y, 0)
    v0 = x0 * W + y0
    visited = np.zeros(N, np.bool_)
    visited[v0] = 1
    stack = np.empty(N, np.int32)
    p = 0
    ret = 0

    def area(x):
        x, y = divmod(x, W)
        return DX[x] * DY[y]

    def push(x):
        nonlocal p, ret
        stack[p] = x
        visited[x] = 1
        ret += area(x)
        p += 1

    def pop():
        nonlocal p
        p -= 1
        return stack[p]

    push(v0)
    move = (1, -1, W, -W)
    while p:
        v = pop()
        for i in range(4):
            if ng[v][i]:
                continue
            w = v + move[i]
            if visited[w]:
                continue
            x, y = divmod(w, W)
            if x == 0 or x == H - 1 or y == 0 or y == W - 1:
                return 0
            push(w)
    return ret


def cc_export():
    from numba.pycc import CC

    cc = CC("my_module")
    signature = "(i8[:],i8[:],i8[:],i8[:],i8[:],i8[:],i8[:],i8[:])"
    cc.export("solve", signature)(solve)
    cc.compile()


if sys.argv[-1] == "ONLINE_JUDGE":
    cc_export()
    exit()
from my_module import solve

N, M = list(map(int, readline().split()))
data = np.int64(read().split())
x = solve(*precompute(N, M, data))
if x == 0:
    print("INF")
else:
    print(x)

import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
INF = 10**9 + 1


def precompute(N, M, data):
    data = data.reshape(-1, 3)
    A, B, C = data[:N].T
    D, E, F = data[N:].T
    X = np.unique(np.concatenate([A, B, D, [0, -INF, INF]]))
    Y = np.unique(np.concatenate([C, E, F, [0, -INF, INF]]))
    A = np.searchsorted(X, A)
    B = np.searchsorted(X, B)
    D = np.searchsorted(X, D)
    C = np.searchsorted(Y, C)
    E = np.searchsorted(Y, E)
    F = np.searchsorted(Y, F)
    return A, B, C, D, E, F, X, Y


def solve(A, B, C, D, E, F, X, Y):
    H, W = len(X), len(Y)
    N = H * W
    DX = X[1:] - X[:-1]
    DY = Y[1:] - Y[:-1]

    def set_ng(A, B, C, D, E, F, H, W):
        ng = np.zeros((H * W, 4), np.bool_)
        for i in range(len(A)):
            for x in range(A[i], B[i]):
                v = x * W + C[i]
                ng[v][1] = 1
                ng[v - 1][0] = 1
        for i in range(len(D)):
            for y in range(E[i], F[i]):
                v = D[i] * W + y
                ng[v][3] = 1
                ng[v - W][2] = 1
        return ng

    ng = set_ng(A, B, C, D, E, F, H, W)
    x0, y0 = np.searchsorted(X, 0), np.searchsorted(Y, 0)
    v0 = x0 * W + y0
    visited = np.zeros(N, np.bool_)
    visited[v0] = 1
    stack = np.empty(N, np.int32)
    p = 0
    ret = 0

    def area(x):
        x, y = divmod(x, W)
        return DX[x] * DY[y]

    def push(x):
        nonlocal p, ret
        stack[p] = x
        visited[x] = 1
        ret += area(x)
        p += 1

    def pop():
        nonlocal p
        p -= 1
        return stack[p]

    push(v0)
    move = (1, -1, W, -W)
    while p:
        v = pop()
        for i in range(4):
            if ng[v][i]:
                continue
            w = v + move[i]
            if visited[w]:
                continue
            x, y = divmod(w, W)
            if x == 0 or x == H - 1 or y == 0 or y == W - 1:
                return 0
            push(w)
    return ret


def cc_export():
    from numba.pycc import CC

    cc = CC("my_module")
    signature = "(i8[:],i8[:],i8[:],i8[:],i8[:],i8[:],i8[:],i8[:])"
    cc.export("solve", signature)(solve)
    cc.compile()


if sys.argv[-1] == "ONLINE_JUDGE":
    cc_export()
    exit()
from my_module import solve

N, M = list(map(int, readline().split()))
data = np.int64(read().split())
x = solve(*precompute(N, M, data))
if x == 0:
    print("INF")
else:
    print(x)

-from numba import njit