#!usr/bin/env python3
import sys
import bisect
from collections import defaultdict,deque
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LIR(n):
    return [LI() for i in range(n)]

def solve():
    n,m = LI()
    p = LIR(n)
    q = LIR(m)
    fx = [-float("inf"),0,float("inf")]
    fy = [-float("inf"),0,float("inf")]
    for a,b,c in p:
        fy.append(a)
        fy.append(a+1e-1)
        fy.append(b)
        fy.append(b+1e-1)
        fx.append(c)
        fx.append(c+1e-1)

    for d,e,f in q:
        fy.append(d)
        fy.append(d+1e-1)
        fx.append(e)
        fx.append(e+1e-1)
        fx.append(f)
        fx.append(f+1e-1)
    fy = list(set(fy))
    fx = list(set(fx))
    fy.sort()
    fx.sort()
    h = len(fy)+1
    w = len(fx)+1
    s = [[0]*w for i in range(h)]
    for a,b,c in p:
        ai = bisect.bisect_left(fy,a)
        bi = bisect.bisect_left(fy,b)
        ci = bisect.bisect_left(fx,c)
        s[ai][ci] += 1
        s[bi+1][ci] -= 1
        s[ai][ci+1] -= 1
        s[bi+1][ci+1] += 1
    for d,e,f in q:
        di = bisect.bisect_left(fy,d)
        ei = bisect.bisect_left(fx,e)
        fi = bisect.bisect_left(fx,f)
        s[di][ei] += 1
        s[di][fi+1] -= 1
        s[di+1][ei] -= 1
        s[di+1][fi+1] += 1
    for i in range(h):
        for j in range(len(fx)):
            s[i][j+1] += s[i][j]
    for i in range(len(fy)):
        for j in range(w):
            s[i+1][j] += s[i][j]
    d = [(1,0),(-1,0),(0,1),(0,-1)]
    sx = bisect.bisect_left(fx,0)
    sy = bisect.bisect_left(fy,0)
    nh,nw = len(fy)-1,len(fx)-1
    for i in range(1,nw-1):
        fx[i+1] = round(fx[i+1])
        fx[i] = fx[i+1]-fx[i]
    for i in range(1,nh-1):
        fy[i+1] = round(fy[i+1])
        fy[i] = fy[i+1]-fy[i]
    fx[0] = -fx[0]
    fy[0] = -fy[0]
    ans = fx[sx]*fy[sy]
    q = deque()
    q.append((sy,sx))
    f = [[1]*nw for i in range(nh)]
    f[sy][sx] = 0
    while q:
        y,x = q.pop()
        for dy,dx in d:
            ny,nx = y+dy,x+dx
            if 0 <= ny < nh and 0 <= nx < nw:
                if f[ny][nx] and not s[ny][nx]:
                    k = fx[nx]*fy[ny]
                    if k == float("inf"):
                        print("INF")
                        return
                    ans += k
                    f[ny][nx] = 0
                    q.appendleft((ny,nx))
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()
