#!/usr/bin/env python3

from collections import defaultdict
from heapq import heappush, heappop
import sys
import bisect

sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
# INF = sys.maxsize
INF = 10 ** 10
# INF = float("inf")


def dp(*x):  # debugprint
    print(*x)


# f = open(sys.argv[1])
# input = f.buffer.readline

N, M = map(int, input().split())
vlines = defaultdict(list)
hlines = defaultdict(list)
vticks = {0}
hticks = {0}

for i in range(N):
    A, B, C = map(int, input().split())
    vlines[C].append((A, B))
    hticks.add(C)
    vticks.update((A, B))

for i in range(M):
    D, E, F = map(int, input().split())
    hlines[D].append((E, F))
    vticks.add(D)
    hticks.update((E, F))

vticks = [-INF] + list(sorted(vticks)) + [INF]
hticks = [-INF] + list(sorted(hticks)) + [INF]


def up(y):
    return vticks[bisect.bisect_left(vticks, y) - 1]


def down(y):
    return vticks[bisect.bisect_left(vticks, y) + 1]


def left(x):
    return hticks[bisect.bisect_left(hticks, x) - 1]


def right(x):
    return hticks[bisect.bisect_left(hticks, x) + 1]


def area(i, j):
    width = hticks[i + 1] - hticks[i]
    height = vticks[j + 1] - vticks[j]
    return width * height


total_area = 0
visited = set()


def visit(i, j):
    global total_area
    if (i, j) in visited:
        return
    # dp("visit: (i,j)", (i, j))
    x = hticks[i]
    y = vticks[j]
    a = area(i, j)
    total_area += a
    visited.add((i, j))
    # visit neighbors
    l = i - 1
    if (l, j) not in visited:
        for a, b in vlines[x]:
            if a <= y < b:
                # blocked
                break
        else:
            # can move left
            to_visit.append((l, j))

    u = j - 1
    if (i, u) not in visited:
        for a, b in hlines[y]:
            if a <= x < b:
                # blocked
                break
        else:
            # can move up
            to_visit.append((i, u))

    r = i + 1
    if (r, j) not in visited:
        for a, b in vlines[hticks[r]]:
            if a <= y < b:
                # blocked
                break
        else:
            # can move left
            to_visit.append((r, j))

    d = j + 1
    if (i, d) not in visited:
        for a, b in hlines[vticks[d]]:
            if a <= x < b:
                # blocked
                break
        else:
            # can move up
            to_visit.append((i, d))


maxH = len(hticks) - 2
maxV = len(vticks) - 2
# dp(": maxH, maxV", maxH, maxV)
i = bisect.bisect_left(hticks, 0)
j = bisect.bisect_left(vticks, 0)
to_visit = [(i, j)]

while to_visit:
    i, j = to_visit.pop()
    # dp(": (i,j)", (i, j))
    if i == 0 or i == maxH or j == 0 or j == maxV:
        print("INF")
        break
    visit(i, j)
    # dp(": to_visit", to_visit)
else:
    print(total_area)


def _test():
    import doctest
    doctest.testmod()
