#!/usr/bin/env python3

import sys, bisect
from queue import Queue
from pprint import pprint
sys.setrecursionlimit(300000)


def solve(N: int, M: int, A: "List[int]", B: "List[int]", C: "List[int]", D: "List[int]", E: "List[int]", F: "List[int]"):
    sx, sy = set(), set()
    for i in range(N):
        sx.add(A[i])
        sx.add(B[i])
        sy.add(C[i])
    for i in range(M):
        sx.add(D[i])
        sy.add(E[i])
        sy.add(F[i])

    sx = list(sx)
    sy = list(sy)
    sx.sort()
    sy.sort()
    h, w = len(sy) * 2, len(sx) * 2
    g = [[0] * w for _ in range(h)]
    for i in range(N):
        ax = bisect.bisect_left(sx, A[i]) * 2
        bx = bisect.bisect_left(sx, B[i]) * 2
        y  = bisect.bisect_left(sy, C[i]) * 2
        for x in range(ax, bx + 1):
            g[y][x] = 1
    for i in range(M):
        x  = bisect.bisect_left(sx, D[i]) * 2
        ay = bisect.bisect_left(sy, E[i]) * 2
        by = bisect.bisect_left(sy, F[i]) * 2
        for y in range(ay, by + 1):
            g[y][x] = 1

    x = bisect.bisect_left(sx, 0) * 2
    y = bisect.bisect_left(sy, 0) * 2
    g[y][x] = 2
    q = Queue()
    q.put((x, y))
    dx = [0, -1, 0, 1]
    dy = [1, 0, -1, 0]
    ret = 0
    #pprint(g)
    while not q.empty():
        x, y = q.get()
        if x % 2 and y % 2:
            xx = sx[x // 2 + 1] - sx[x // 2]
            yy = sy[y // 2 + 1] - sy[y // 2]
            ret += xx * yy
        for k in range(len(dx)):
            tx, ty = x + dx[k], y + dy[k]
            if 0 <= tx < w and 0 <= ty < h and g[ty][tx] == 0:
                if tx == 0 or tx == w - 1 or ty == 0 or ty == h - 1:
                    print('INF')
                    return
                g[ty][tx] = 2
                q.put((tx, ty))
    #pprint(g)

    #ret = 0
    #for y in range(h):
    #    for x in range(w):
    #        if g[y][x] != 2:
    #            continue
    #        if x == 0 or x == w - 1 or y == 0 or y == h - 1:
    #            print('INF')
    #            return
    #        if x % 2 == 0 or y % 2 == 0:
    #            continue
    #        xx = sx[x // 2 + 1] - sx[x // 2]
    #        yy = sy[y // 2 + 1] - sy[y // 2]
    #        ret += xx * yy
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    C = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
        C[i] = int(next(tokens))
    D = [int()] * (M)  # type: "List[int]"
    E = [int()] * (M)  # type: "List[int]"
    F = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        D[i] = int(next(tokens))
        E[i] = int(next(tokens))
        F[i] = int(next(tokens))
    solve(N, M, A, B, C, D, E, F)

if __name__ == '__main__':
    main()
