# Original solution
#!/usr/bin/python3


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

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

lvs = []
for i in range(n):
    (a, b, c) = list(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) = list(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)




# Optimized solution
#!/usr/bin/python3


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

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

lvs = []
for i in range(n):
    (a, b, c) = list(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) = list(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)