### BUGGY CODE ###

#!/usr/bin/python3
from collections import defaultdict

(n, m) = map(int, input().split())

xti = {}
yti = {}
xti[0] = -1
yti[0] = -1

lvs = []
for i in range(n):
    (a, b, c) = map(int, input().split())
    yti[a] = -1
    yti[b] = -1   
    xti[c] = -1
    lvs.append((a, b, c))

lhs = []
for i in range(m):
    (d, e, f) = map(int, input().split())
    yti[d] = -1
    xti[e] = -1   
    xti[f] = -1
    lhs.append((d, e, f))

xs = sorted(xti.keys())
for (i, x) in enumerate(xs):
    xti[x] = i

ys = sorted(yti.keys())
for (i, y) in enumerate(ys):
    yti[y] = i

fi = [ [ 0 for x in range(len(xs) * 2) ] for y in range(len(ys) * 2) ]

for (a, b, c) in lvs:
    x = xti[c] * 2
    for y in range(yti[a] * 2, yti[b] * 2 + 1):
        fi[y][x] = -1

for (d, e, f) in lhs:
    y = yti[d] * 2
    for x in range(xti[e] * 2, xti[f] * 2 + 1):
        fi[y][x] = -1

q = [(xti[0] * 2, yti[0] * 2)]

while q:
    (cx, cy) = q.pop(-1)
    if cx < 0 or cx >= len(xs) * 2 or cy < 0 or cy >= len(ys) * 2:
        continue
    
    if fi[cy][cx] != 0:
        continue

    fi[cy][cx] = 1
    q.append((cx, cy - 1))
    q.append((cx + 1, cy))
    q.append((cx, cy + 1))
    q.append((cx - 1, cy))

#for xl in fi:
#    print(xl)

s = 0
for y in range(len(ys) * 2):
    for x in range(len(xs) * 2):
        if fi[y][x] <= 0:
            continue
        if x == 0 or x == len(xs) * 2 - 1 or y == 0 or y == len(ys) * 2 - 1:
            print('INF')
            exit()

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

print(s)


### FIXED CODE ###

#!/usr/bin/python3


(n, m) = map(int, input().split())

xti = {}
yti = {}
xti[0] = -1
yti[0] = -1

lvs = []
for i in range(n):
    (a, b, c) = map(int, input().split())
    yti[a] = -1
    yti[b] = -1   
    xti[c] = -1
    lvs.append((a, b, c))

lhs = []
for i in range(m):
    (d, e, f) = map(int, input().split())
    yti[d] = -1
    xti[e] = -1   
    xti[f] = -1
    lhs.append((d, e, f))

xs = sorted(xti.keys())
for (i, x) in enumerate(xs):
    xti[x] = i
    
ys = sorted(yti.keys())
for (i, y) in enumerate(ys):
    yti[y] = i

xsl = (len(xs) + 1) * 2
ysl = (len(ys) + 1) * 2

fi = [ [ 0 for x in range(xsl) ] for y in range(ysl) ]

for (a, b, c) in lvs:
    x = xti[c] * 2 + 1
    for y in range(yti[a] * 2 + 1, yti[b] * 2 + 1 + 1):
        fi[y][x] = 2

for (d, e, f) in lhs:
    y = yti[d] * 2 + 1
    for x in range(xti[e] * 2 + 1, xti[f] * 2 + 1 + 1):
        fi[y][x] = 2

(cx, cy) = (xti[0] * 2, yti[0] * 2)
q = []
q.append((cx, cy))
fi[cy][cx] = 1
s = (xs[cx // 2] - xs[(cx - 1)// 2]) * (ys[cy // 2] - ys[(cy - 1) // 2])
dxs = [0, 1, 0, -1]
dys = [1, 0, -1, 0]

while q:
    (x, y) = q.pop(-1)

    for i in range(4):
        cx = x + dxs[i] * 2
        cy = y + dys[i] * 2
    
        if fi[cy][cx] != 0:
            continue

        pcx = x + dxs[i]
        pcy = y + dys[i]
        if fi[pcy][pcx] == 2:
            continue
        
        
        if cx == 0 or cx == xsl - 2 or cy == 0 or cy == ysl - 2:
            print('INF')
            exit()

        fi[cy][cx] = 1
        s += (xs[cx // 2] - xs[(cx - 1)// 2]) * (ys[cy // 2] - ys[(cy - 1) // 2])
        q.append((cx, cy))

print(s)

#for xl in fi:
#    print(xl)