from collections import defaultdict, deque

N, M = map(int, input().split())

LV = []
LH = []

mp_X = defaultdict(int)
mp_Y = defaultdict(int)

for _ in range(N):
    a,b,c = map(int, input().split())
    mp_X[a] = 0
    mp_X[b] = 0
    mp_Y[c] = 0
    LH.append((a,b,c))

for _ in range(M):
    d,e,f = map(int, input().split())
    mp_X[d] = 0
    mp_Y[e] = 0
    mp_Y[f] = 0
    LV.append((e,f,d))

sX = []
sY = []

for i, k in enumerate(sorted(mp_X)):
    mp_X[k] = i
    sX.append(k)
for i, k in enumerate(sorted(mp_Y)):
    mp_Y[k] = i
    sY.append(k)

sizeX = len(mp_X) * 2 - 1
sizeY = len(mp_Y) * 2 - 1

d = [[0 for _ in range(sizeY)] for _ in range(sizeX)]

for x1,x2,y in LH:
    for x in range(mp_X[x1]*2,mp_X[x2]*2+1):
        d[x][mp_Y[y]*2] = -1

for y1,y2,x in LV:
    for y in range(mp_Y[y1]*2,mp_Y[y2]*2+1):
        d[mp_X[x]*2][y] = -1

dx = [0,1,0,-1]
dy = [1,0,-1,0]

q = deque()
cx, cy = mp_X[0]*2, mp_Y[0]*2
d[cx][cy] = 1
q.append((cx,cy))
while q:
    cx, cy = q.popleft()
    for i in range(4):
        nx, ny = cx + dx[i], cy + dy[i]
        if abs(d[nx][ny]) == 1:
            continue
        d[nx][ny] = 1
        q.append((nx,ny))

ans = 0
for x in range(sizeX):
    for y in range(sizeY):
        if d[x][0] == 1 or d[x][sizeY-1] == 1 \
            or d[0][y] == 1 or d[sizeX-1][y] == 1:
            print("INF")
            break
        if x % 2 == 0 or y % 2 == 0:
            continue
        if d[x][y] == 1:
            ans += (sX[x//2+1]-sX[x//2])*(sY[y//2+1]-sY[y//2])
    else:
        continue
    break
else:
    print(ans)