import sys

# from collections import deque

max_int = 1000000001  # 10^9+1
min_int = -max_int

n, m = map(int, sys.stdin.readline().split())

xs = {0}
ys = {0}

hor = {}  # [x => [[a,b], [a,b]], ...]
ver = {}

for _n in range(n):
    a, b, c = map(int, sys.stdin.readline().split())
    xs.add(a)
    xs.add(b)
    ys.add(c)
    if c not in ver:
        ver[c] = [[a, b]]
    else:
        ver[c].append([a, b])

for _m in range(m):
    d, e, f = map(int, sys.stdin.readline().split())
    xs.add(d)
    ys.add(e)
    ys.add(f)
    if d not in hor:
        hor[d] = [[e, f]]
    else:
        hor[d].append([e, f])

xs = list(xs)
xs.sort()
x0 = 0
for i in range(len(xs)):
    if xs[i] == 0:
        x0 = i
        break

ys = list(ys)
ys.sort()
y0 = 0
for j in range(len(ys)):
    if ys[j] == 0:
        y0 = j
        break

if x0 == 0 or y0 == 0 or x0 == len(xs) - 1 or y0 == len(ys) - 1:
    print('INF')
    exit()

ans = 0
q = [(x0 - 1, y0 - 1, x0, y0)]
# pretends = [(x0 - 1, y0 - 1, x0, y0)]
visited = set()

while q:
    xl_, yl_, xr_, yr_ = q.pop()
    if (xl_, yl_, xr_, yr_) in visited:
        continue
    visited.add((xl_, yl_, xr_, yr_))
    if xl_ < 0 or yl_ < 0 or xr_ >= len(xs) or yr_ >= len(ys):
        print('INF')
        exit()
    xl = xs[xl_]
    xr = xs[xr_]
    yl = ys[yl_]
    yr = ys[yr_]
    ans += (xr - xl) * (yr - yl)
    if xl in hor:
        for lb, rb in hor[xl]:
            if lb <= yl and rb >= yr:
                break
        else:
            q.append((xl_ - 1, yl_, xr_ - 1, yr_))
    else:
        q.append((xl_ - 1, yl_, xr_ - 1, yr_))

    if xr in hor:
        for lb, rb in hor[xr]:
            if lb <= yl and rb >= yr:
                break
        else:
            q.append((xl_ + 1, yl_, xr_ + 1, yr_))
    else:
        q.append((xl_ + 1, yl_, xr_ + 1, yr_))

    if yl in ver:
        for ub, db in ver[yl]:
            if ub <= xl and db >= xr:
                break
        else:
            q.append((xl_, yl_ - 1, xr_, yr_ - 1))
    else:
        q.append((xl_, yl_ - 1, xr_, yr_ - 1))

    if yr in ver:
        for ub, db in ver[yr]:
            if ub <= xl and db >= xr:
                break
        else:
            q.append((xl_, yl_ + 1, xr_, yr_ + 1))
    else:
        q.append((xl_, yl_ + 1, xr_, yr_ + 1))
    # print(new_pretends, ans)
    # break

print(ans)
