# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n,m = [int(i) for i in readline().split()]
tate = [[int(i) for i in readline().split()] for _ in range(n)]
yoko = [[int(i) for i in readline().split()] for _ in range(m)]

INF = 10**9+5
hcoord = {-INF,0,INF}
wcoord = {-INF,0,INF}

for a,b,c in tate: # (a,c) to (b,c)
    hcoord.add(a)
    hcoord.add(b)
    wcoord.add(c)
for d,e,f in yoko: # (d,e) to (d,f)
    hcoord.add(d)
    wcoord.add(e)
    wcoord.add(f)

hcoord = list(sorted(hcoord))
wcoord = list(sorted(wcoord))

zaatu_x = {a:i for i,a in enumerate(sorted(hcoord))}
zaatu_y = {a:i for i,a in enumerate(sorted(wcoord))}

P = len(hcoord)
Q = len(wcoord)

ok_h = [[1 for y in range(Q-1)] for x in range(P-1)] #縦に移動できるか？
ok_w = [[1 for y in range(Q-1)] for x in range(P-1)] #横に移動できるか？

for y in range(Q-1):
    ok_h[P-2][y] = 0
for x in range(P-1):
    ok_w[x][Q-2] = 0

for a,b,c in tate: # (a,c) to (b,c)
    xa = zaatu_x[a]
    xb = zaatu_x[b]
    yc = zaatu_y[c]
    for i in range(xa,xb):
        ok_w[i][yc-1] = 0

for d,e,f in yoko: # (d,e) to (d,f)
    ye = zaatu_y[e]
    yf = zaatu_y[f]
    xd = zaatu_x[d]
    for i in range(ye,yf):
        ok_h[xd-1][i] = 0

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

x0 = zaatu_x[0]
y0 = zaatu_y[0]
used = [[0 for y in range(Q-1)] for x in range(P-1)]

from collections import deque
q = deque([(x0,y0)])
used[x0][y0] = 1
while q:
    x,y = q.popleft()
    for i in range(4):
        nx = x+dx[i]
        ny = y+dy[i]
        if nx < 0 or ny < 0 or nx >= P-1 or ny >= Q-1: continue #枠外
        #4方向
        if i==0 and ok_h[x][y]==0: continue
        if i==2 and ok_h[nx][ny]==0: continue
        if i==1 and ok_w[x][y]==0: continue
        if i==3 and ok_w[nx][ny]==0: continue
        
        if used[nx][ny] == 0:
            used[nx][ny] = 1
            q.append((nx,ny))


#print(used)

if used[0][0] == 1:
    print("INF")
else:
    ans = 0
    for i in range(P-1):
        for j in range(Q-1):
            if used[i][j] == 1:
                ans += (hcoord[i+1]-hcoord[i])*(wcoord[j+1]-wcoord[j])
    print(ans)

