# coding: utf-8
from collections import deque
N,M=map(int,input().split())
tate=[]
yoko=[]
INF=10**20
MAP=[[INF for i in range(N+1)] for j in range(M+1)]
visited=[[False for i in range(N+1)] for j in range(M+1)]
tkabe=[[False for i in range(M-1)] for j in range(N)]
ykabe=[[False for i in range(N-1)] for j in range(M)]
Cl=[]
Dl=[]

for i in range(N):
    A,B,C=map(int,input().split())
    tate.append([C,[A,B]])
    Cl.append(C)
    
for i in range(M):
    D,E,F=map(int,input().split())
    yoko.append([D,[E,F]])
    Dl.append(D)

tate.sort()
yoko.sort()
Cl.sort()
Dl.sort()

for i in range(N):
    for j in range(M-1):
        a,b=tate[i][1]
        if a<=Dl[j] and Dl[j+1]<=b:
            tkabe[i][j]=True
        if Dl[j]<=0 and 0<=Dl[j+1]:
            sy=j+1

for i in range(M):
    for j in range(N-1):
        e,f=yoko[i][1]
        if e<=Cl[j] and Cl[j+1]<=f:
            ykabe[i][j]=True
        if Cl[j]<=0 and 0<=Cl[j+1]:
            sx=j+1
            
for i in range(M-1):
    for j in range(N-1):
        MAP[i+1][j+1]=(Cl[j+1]-Cl[j])*(Dl[i+1]-Dl[i])
        
dx=[1,0,-1,0]
dy=[0,1,0,-1]

queue=deque()
ans=MAP[sy][sx]
visited[sy][sx]=True
queue.append([sy,sx])

while len(queue)>0:
    y,x=queue.popleft()
    for k in range(4):
        nx=x+dx[k]
        ny=y+dy[k]
        if not(k==0 and tkabe[nx][ny-1]) and  not(k==2 and tkabe[nx-1][ny-1]) and not(k==1 and tkabe[ny][nx-1]) and not(k==3 and tkabe[ny+1][nx-1]):
            if 0<=ny<M+1 and 0<=nx<N+1:
                if not(visited[ny][nx]):
                    ans+=MAP[ny][nx]
                    queue.append([ny,nx])
                    visited[ny][nx]=True

if ans>=10**20-1:
    print("INF")
else:
    print(ans)
