import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

n,m=l_in()

yoko=[]
tate=[]
xs=set([0])
ys=set([0])

# yoko

for _ in range(n):
    a,b,c=l_in()
    yoko.append((a,b,c))
    xs.add(a)
    xs.add(b)
    ys.add(c)

for _ in range(m):
    d,e,f=l_in()
    tate.append((d,e,f))
    xs.add(d)
    ys.add(e)
    ys.add(f)

xdict={}
ydict={}

xs= sorted(xs)
ys= sorted(ys)

for i, x in enumerate(sorted(xs)):
    xdict[x] = i
for i, y in enumerate(sorted(ys)):
    ydict[y] = i

h = 2*len(xs)
w = 2*len(ys)
M = [[0]*w for _ in range(h)]

for a,b,c in yoko:
    a,b,c = xdict[a]*2, xdict[b]*2, ydict[c]*2
    for x in range(a,b+1):
        M[x][c] = 1

for d,e,f in tate:
    d,e,f = xdict[d]*2, ydict[e]*2, ydict[f]*2
    for y in range(e,f+1):
        M[d][y] = 1

from collections import deque
q=deque()

Dx=[1,0,-1,0]
Dy=[0,1,0,-1]

q.append((xdict[0]*2, ydict[0]*2))

while len(q) > 0:
    x,y = q.popleft()
    for dx, dy in zip(Dx,Dy):
        x2 = x+dx
        y2 = y+dy
        if x2 < 0 or x2 >= h:
            continue
        if y2 < 0 or y2 >= w:
            continue
        if M[x2][y2] != 0:
            continue
        M[x2][y2] = 2
        q.append((x2,y2))

#[print(m) for m in M]

res = 0
for x in range(h):
    for y in range(w):
        if M[x][y] != 2:
            continue
        if x==0 or x == h-1 or y == 0 or y == w-1:
            print("INF")
            exit()
        if x%2 == 0 or y%2 == 0:
            continue

        res += (xs[x//2+1] - xs[x//2])*(ys[y//2+1] - ys[y//2])

print(res)

        
        
    
