#!/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) * 2
ysl = len(ys) * 2

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

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

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

xsd = [ xs[i + 1] - xs[i] for i in range(len(xs) - 1) ]
ysd = [ ys[i + 1] - ys[i] for i in range(len(ys) - 1) ]

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

    if x > 0:
        cx = x - 1
        cy = y
    
        if fi[cy][cx] == 0:
            if cx == 0 or cx == xsl - 1 or cy == 0 or cy == ysl - 1:
                print('INF')
                exit()

            fi[cy][cx] = 1
            if cx % 2 == 1 and cy % 2 == 1:
                s += xsd[cx // 2] * ysd[cy // 2]
            q.append((cx, cy))

    if x < xsl - 1:
        cx = x + 1
        cy = y
    
        if fi[cy][cx] == 0:
            if cx == 0 or cx == xsl - 1 or cy == 0 or cy == ysl - 1:
                print('INF')
                exit()

            fi[cy][cx] = 1
            if cx % 2 == 1 and cy % 2 == 1:
                s += xsd[cx // 2] * ysd[cy // 2]                
            q.append((cx, cy))
            
    if y > 0:
        cx = x
        cy = y - 1
    
        if fi[cy][cx] == 0:
            if cx == 0 or cx == xsl - 1 or cy == 0 or cy == ysl - 1:
                print('INF')
                exit()

            fi[cy][cx] = 1
            if cx % 2 == 1 and cy % 2 == 1:
                s += xsd[cx // 2] * ysd[cy // 2]                                
            q.append((cx, cy))

    if y < ysl - 1:
        cx = x
        cy = y + 1
    
        if fi[cy][cx] == 0:
            if cx == 0 or cx == xsl - 1 or cy == 0 or cy == ysl - 1:
                print('INF')
                exit()

            fi[cy][cx] = 1
            if cx % 2 == 1 and cy % 2 == 1:
                s += xsd[cx // 2] * ysd[cy // 2]                                                
            q.append((cx, cy))
            

print(s)
#for xl in fi:
#    print(xl)


