tate,yoko=map(int,input().split())


yy=set([0])
xx=set([0])

yyy=[]
for _ in range(tate):
    y1,y2,x=map(int,input().split())
    yy.add(y1)
    yy.add(y2)
    xx.add(x)
    yyy.append([y1,y2,x])


xxx=[[0,0,0]]
for _ in range(yoko):
    y,x1,x2=map(int,input().split())
    xx.add(x1)
    xx.add(x2)
    yy.add(y)
    xxx.append([y,x1,x2])

xx=list(xx)
yy=list(yy)
xx.sort()
yy.sort()

y=1
yindex={}
yindexrev={}
for v in yy:
    yindex[v]=y
    yindexrev[y]=v
    y+=2

x=1
xindex={}
xindexrev={}
for v in xx:
    xindex[v]=x
    xindexrev[x]=v
    x+=2

maze=[[" "]*x for _ in range(y)]

for item in yyy:
    [y1,y2,x]=item
    for y in range(len(maze)):
        maze[y][xindex[x]]="."
    
    for x3 in range(len(maze[0])):
        if maze[yindex[y1]][x3]==" ":
            maze[yindex[y1]][x3]="."
        if maze[yindex[y2]][x3]==" ":
            maze[yindex[y2]][x3]="."
    
    for y in range(yindex[y1],yindex[y2]+1):
        maze[y][xindex[x]]="#"

for item in xxx:
    [y,x1,x2]=item
    for x in range(len(maze[0])):
        if maze[yindex[y]][x]==" ":
            maze[yindex[y]][x]="."
    for y3 in range(len(maze)):
        
        if maze[y3][xindex[x1]]==" ":
            maze[y3][xindex[x1]]="."
        if maze[y3][xindex[x2]]==" ":
            maze[y3][xindex[x2]]="."
    for x in range(xindex[x1],xindex[x2]+1):
        maze[yindex[y]][x]="#"

cnt=0
d=[(yindex[0],xindex[0])]
from collections import deque
stack = deque(d)

#for item in maze:
#    print("".join(item))

while len(stack)>0:
    [y,x]=stack.popleft()
    #print(y,x)
    if maze[y][x]==".":
        maze[y][x]="0"
    elif maze[y][x]==" ":
        if y-1<=0 or x-1<=0 or y+1>=len(maze)-1 or x+1>=len(maze[0])-1:
            print("INF")
            exit() 
        
        tmp=(yindexrev[y+1]-yindexrev[y-1])*(xindexrev[x+1]-xindexrev[x-1])
        maze[y][x]=str(tmp)
        cnt+=tmp
    
    for (my,mx) in [(1,0),(0,1),(-1,0),(0,-1)]:
        #print(y+my,x+mx)
        if my+y==0 or my+y==len(maze)-1 or mx+x==0 or mx+x==len(maze[0])-1:
            print("INF")
            exit()
        if maze[y+my][x+mx] in [" ","."]:
            stack.append((y+my,x+mx)) 
        


#for item in maze:
#    print("".join(item))
    



print(cnt)




