import sys
input = sys.stdin.readline

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

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

vert = []
for _ in range(n):
    a, b, c = map(int, input().split())
    xs.add(a)
    xs.add(b)
    ys.add(c)
    vert.append((a,b,c))

hor = []
for _ in range(m):
    d, e, f = map(int, input().split())
    xs.add(d)
    ys.add(e)
    ys.add(f)
    hor.append((d,e,f))

xs = list(xs)
ys = list(ys)
xs.sort()
ys.sort()

revX = dict()
revY = dict()
for i in range(len(xs)):
    revX[xs[i]] = i
for i in range(len(ys)):
    revY[ys[i]] = i

width = len(xs) + 1
height = len(ys) + 1

visited = [[False] * height for _ in range(width)]
area = [[0] * height for _ in range(width)]
for i in range(1, width - 1):
    for j in range(1, height - 1):
        area[i][j] = (xs[i] - xs[i-1]) * (ys[j] - ys[j-1])
        
adj = [[15]*height for _ in range(width)]
for i in range(width):
    adj[i][0] &= 14
    adj[i][height - 1] &= 13
for j in range(height):
    adj[0][j] &= 11
    adj[width - 1][j] &= 7

for a, b, c in vert:
    ra, rb, rc = revX[a], revX[b], revY[c]
    for i in range(ra + 1, rb + 1):
        adj[i][rc] &= 13
        adj[i][rc + 1] &= 14

for d, e, f in hor:
    rd, re, rf = revX[d], revY[e], revY[f]
    for j in range(re + 1, rf + 1):
        adj[rd][j] &= 7
        adj[rd + 1][j] &= 11

dX = [0,0,-1,1]
dY = [-1,1,0,0]

stack = []
start = (revX[0], revY[0])
stack.append(start)
visited[start[0]][start[1]] = True
out = area[start[0]][start[1]]
inf = False
while stack:
    nexX, nexY = stack.pop()
    poss = adj[nexX][nexY]
    for d in range(4):
        if poss & (1 << d):
            newX = nexX + dX[d]
            newY = nexY + dY[d]
            if not visited[newX][newY]:
                visited[newX][newY] = True
                stack.append((newX, newY))
                newA = area[newX][newY]
                out += newA
                inf |= newA == 0

if inf:
    print('INF')
else:
    print(out)
            
        
