#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

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

    for d,e,f in q:
        fy.add(d)
        fy.add(d+1e-1)
        fy.add(d-1e-1)
        fx.add(e)
        fx.add(e+1e-1)
        fx.add(e-1e-1)
        fx.add(f)
        fx.add(f+1e-1)
        fx.add(f-1e-1)
    fy = list(fy)
    fx = list(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)]
    ans = 0
    sx = bisect.bisect_left(fx,0)
    sy = bisect.bisect_left(fy,0)
    nh,nw = len(fy)-1,len(fx)-1
    lx = [float("inf")]*nw
    ly = [float("inf")]*nh
    fx[1] = round(fx[1])
    fy[1] = round(fy[1])
    for i in range(1,nw-1):
        fx[i+1] = round(fx[i+1])
        lx[i] = fx[i+1]-fx[i]
    for i in range(1,nh-1):
        fy[i+1] = round(fy[i+1])
        ly[i] = fy[i+1]-fy[i]

    ans += lx[sx]*ly[sy]
    q = [(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 = lx[nx]*ly[ny]
                    if k == float("inf"):
                        print("INF")
                        return
                    ans += k
                    f[ny][nx] = 0
                    q.append((ny,nx))
    print(ans)
    return

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