### 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)

event = [[] for _ in range(Lx)]
for X, st, en in Hp:
    event[Cex[X]].append((0, Cey[st], Cey[en]))
for st, en, Y in Wp:
    event[Cex[st]].append((1, Cey[Y], 0))
    event[Cex[en]].append((-1, Cey[Y], 0))

geta = Ly

banned = [[] for _ in range(Lx*Ly)]

table = [0]*Ly
for xi in range(Lx):
    for a, b, c in event[xi]:
        if a == 0:
            for yi in range(b, c):
                banned[(xi-1)*geta+yi].append(geta)
                banned[xi*geta+yi].append(-geta)
        elif a == 1:
            table[b] = 1
        else:
            table[b] = 0
    for i in range(Ly):
        if table[i]:
            if xi*geta+i == 47:
                pass
            banned[xi*geta+i].append(-1)
            banned[xi*geta+i-1].append(1)
                
ed = set()
for i in range(Lx):
    ed.add(i*geta)
    ed.add(i*geta+Ly-1)
for j in range(Ly):
    ed.add(j)
    ed.add((Lx-1)*geta+j)
used = set()
st = Cex[0]*geta+Cey[0]
stack = [st]
DIREC = (1, -1, geta, -geta)

while stack:
    vn = stack.pop()
    if vn in ed:
        continue
    for d in DIREC:
        if d in banned[vn]:
            continue
        vf = vn+d
        if vf not in used:
            used.add(vf)
            stack.append(vf)

if ed&used:
    print('INF')
else:
    area = 0
    for k in used:
        x, y = divmod(k, geta)
        area += (Elx[x+1]-Elx[x])*(Ely[y+1]-Ely[y])
    print(area)
    



### 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)