### BUGGY CODE ###

import sys
readline = sys.stdin.readline

def compress(L):
    L2 = list(set(L))
    L2.sort()
    C = {v : k for k, v in enumerate(L2)}
    return L2, C

N, M = map(int, readline().split())
INF = 10**9+7

Wp = [tuple(map(int, readline().split())) for _ in range(N)]
Hp = [tuple(map(int, readline().split())) for _ in range(M)]


epx = [0, INF, -INF]
epy = [0, INF, -INF]

for X, st, en in Hp:
    epx.append(X)
    epy.append(st)
    epy.append(en)

for st, en, Y in Wp:
    epy.append(Y)
    epx.append(st)
    epx.append(en)
    

Elx, Cex = compress(epx)
Ely, Cey = compress(epy)
Lx = len(Elx)
Ly = len(Ely)

geta = Ly

UD = [[0]*(Lx+1) for _ in range(Ly+1)]
LR = [[0]*(Lx+1) for _ in range(Ly+1)]
for X, st, en in Hp:
    LR[Cey[st]][Cex[X]] += 1
    LR[Cey[en]][Cex[X]] -= 1
for st, en, Y in Wp:
    UD[Cey[Y]][Cex[st]] += 1
    UD[Cey[Y]][Cex[en]] -= 1

for x in range(1, Lx):
    for y in range(Ly):
        UD[y][x] += UD[y][x-1]

for y in range(1, Ly):
    for x in range(Lx):
        LR[y][x] += LR[y-1][x]
      
ed = set()
for i in range(Lx):
    ed.add((i, 0))
    ed.add((i, Ly-1))
for j in range(Ly):
    ed.add((0, j))
    ed.add((Lx-1, j))

sx, sy = Cex[0], Cey[0]
st = (sx, sy)
stack = [st]
used = [[False]*Lx for _ in range(Ly)]
used[sy][sx] = True
ans = 'INF'
area = 0
while stack:
    vx, vy = stack.pop()
    if (vx, vy) in ed:
        break
    area += (Elx[vx+1]-Elx[vx])*(Ely[vy+1]-Ely[vy])
    if not UD[vy+1][vx] and not used[vy+1][vx]:
        used[vy+1][vx] = True
        stack.append((vx, vy+1))
    if not UD[vy][vx] and not used[vy-1][vx]:
        used[vy-1][vx] = True
        stack.append((vx, vy-1))
    if not LR[vy][vx+1] and not used[vy][vx+1]:
        used[vy][vx+1] = True
        stack.append((vx+1, vy))
    if not LR[vy][vx] and not used[vy][vx-1]:
        used[vy][vx-1] = True
        stack.append((vx-1, vy))

else:
    ans = area
print(ans)

### FIXED CODE ###

import sys
readline = sys.stdin.readline

def compress(L):
    L2 = list(set(L))
    L2.sort()
    C = {v : k for k, v in enumerate(L2)}
    return L2, C

N, M = map(int, readline().split())
INF = 10**9+7

Wp = [tuple(map(int, readline().split())) for _ in range(N)]
Hp = [tuple(map(int, readline().split())) for _ in range(M)]


epx = [0, INF, -INF]
epy = [0, INF, -INF]

for X, st, en in Hp:
    epx.append(X)
    epy.append(st)
    epy.append(en)

for st, en, Y in Wp:
    epy.append(Y)
    epx.append(st)
    epx.append(en)
    

Elx, Cex = compress(epx)
Ely, Cey = compress(epy)
Lx = len(Elx)
Ly = len(Ely)


UD = [[0]*(Lx+1) for _ in range(Ly+1)]
LR = [[0]*(Lx+1) for _ in range(Ly+1)]
for X, st, en in Hp:
    LR[Cey[st]][Cex[X]] += 1
    LR[Cey[en]][Cex[X]] -= 1
for st, en, Y in Wp:
    UD[Cey[Y]][Cex[st]] += 1
    UD[Cey[Y]][Cex[en]] -= 1

for x in range(1, Lx):
    for y in range(Ly):
        UD[y][x] += UD[y][x-1]

for y in range(1, Ly):
    for x in range(Lx):
        LR[y][x] += LR[y-1][x]
      
ed = set()
for i in range(Lx):
    ed.add((i, 0))
    ed.add((i, Ly-1))
for j in range(Ly):
    ed.add((0, j))
    ed.add((Lx-1, j))

geta = Ly
st = Cex[0]*geta + Cey[0]
stack = [st]
used = [False]*(Lx*Ly)
used[st] = True
ans = 'INF'
area = 0
while stack:
    vx, vy = divmod(stack.pop(), geta)
    if (vx, vy) in ed:
        break
    area += (Elx[vx+1]-Elx[vx])*(Ely[vy+1]-Ely[vy])
    if not UD[vy+1][vx] and not used[vx*geta+vy+1]:
        used[vx*geta+vy+1] = True
        stack.append(vx*geta+vy+1)
    if not UD[vy][vx] and not used[vx*geta+vy-1]:
        used[vx*geta+vy-1] = True
        stack.append(vx*geta+vy-1)
    if not LR[vy][vx+1] and not used[(vx+1)*geta+vy]:
        used[(vx+1)*geta+vy] = True
        stack.append((vx+1)*geta+vy)
    if not LR[vy][vx] and not used[(vx-1)*geta+vy]:
        used[(vx-1)*geta+vy] = True
        stack.append((vx-1)*geta+vy)

else:
    ans = area
print(ans)