mod = 1000000007
eps = 10**-9


def main():
    import sys
    from collections import deque
    input = sys.stdin.buffer.readline

    def fin():
        print("INF")
        exit()

    N, M = map(int, input().split())
    X = set()
    X.add(-10**9-1)
    X.add(0)
    X.add(10**9+1)
    Y = set()
    Y.add(-10**9-1)
    Y.add(0)
    Y.add(10**9+1)
    ABC = []
    DEF = []
    for _ in range(N):
        a, b, c = map(int, input().split())
        X.add(a)
        X.add(b)
        Y.add(c)
        ABC.append((a, b, c))
    for _ in range(M):
        d, e, f = map(int, input().split())
        X.add(d)
        Y.add(e)
        Y.add(f)
        DEF.append((d, e, f))
    X = sorted(list(X))
    Y = sorted(list(Y))
    x2i = {x: i for i, x in enumerate(X)}
    y2j = {y: j for j, y in enumerate(Y)}
    LX = len(X)
    LY = len(Y)
    ABCwall = [set() for _ in range(LY)]
    for a, b, c in ABC:
        i0 = x2i[a]
        i1 = x2i[b]
        j = y2j[c]
        for i in range(i0, i1):
            ABCwall[j].add(i)
    DEFwall = [set() for _ in range(LX)]
    for d, e, f in DEF:
        i = x2i[d]
        j0 = y2j[e]
        j1 = y2j[f]
        for j in range(j0, j1):
            DEFwall[i].add(j)

    ii = x2i[0]
    jj = y2j[0]
    que = deque()
    que.append((ii, jj))
    seen = [[0] * (LY-1) for _ in range(LX-1)]
    seen[ii][jj] = 1
    ans = 0
    while que:
        i, j = que.popleft()
        ans += (X[i+1] - X[i]) * (Y[j+1] - Y[j])

        # x inc
        if j not in DEFwall[i+1]:
            if i == LX - 2:
                fin()
            if not seen[i+1][j]:
                que.append((i+1, j))
                seen[i+1][j] = 1

        # x dec
        if j not in DEFwall[i]:
            if i == 1:
                fin()
            if not seen[i-1][j]:
                que.append((i-1, j))
                seen[i-1][j] = 1

        # y inc
        if i not in ABCwall[j+1]:
            if j == LY - 2:
                fin()
            if not seen[i][j+1]:
                que.append((i, j+1))
                seen[i][j+1] = 1

        # y dec
        if i not in ABCwall[j]:
            if j == 1:
                fin()
            if not seen[i][j-1]:
                que.append((i, j-1))
                seen[i][j-1] = 1
    print(ans)


if __name__ == '__main__':
    main()
