import sys

int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n,m=MI()
    xx=set([0])
    yy=set([0])
    vl=[]
    hl=[]
    for _ in range(n):
        a,b,c=MI()
        xx.add(a)
        xx.add(b)
        yy.add(c)
        vl.append((a,b,c))
    for _ in range(m):
        a,b,c=MI()
        xx.add(a)
        yy.add(b)
        yy.add(c)
        hl.append((b,c,a))

    dex=list(sorted(xx))
    dey=list(sorted(yy))
    cox={x:i for i,x in enumerate(dex)}
    coy={x:i for i,x in enumerate(dey)}
    xn=len(dex)
    yn=len(dey)

    tt=[[9]*yn*2 for _ in range(xn*2)]
    for x0,x1,y in vl:
        for i in range(cox[x0]*2,cox[x1]*2):
            tt[i][coy[y]*2]=0
    for y0,y1,x in hl:
        for j in range(coy[y0]*2,coy[y1]*2):
            tt[cox[x]*2][j]=0
    p2D(tt)

    si,sj=cox[0]*2,coy[0]*2
    stack=[(si,sj)]
    tt[si][sj]=1
    dij=[(1,0),(0,1),(-1,0),(0,-1)]
    while stack:
        i,j=stack.pop()
        for di,dj in dij:
            ni,nj=i+di,j+dj
            if ni<0 or nj<0 or ni>=2*xn or nj>=2*yn:continue
            if tt[ni][nj]!=9:continue
            if ni==0 or nj==0 or ni==2*xn-1 or nj==2*yn-1:
                print("INF")
                #p2D(tt)
                exit()
            tt[ni][nj]=1
            stack.append((ni,nj))
    p2D(tt)

    ans=0
    for i in range(1,xn*2,2):
        for j in range(1,yn*2,2):
            if tt[i][j]==1:
                ans+=(dex[i//2+1]-dex[i//2])*(dey[j//2+1]-dex[j//2])
    print(ans)

main()