from collections import defaultdict, deque

def main():
    N, M = map(int, input().split())

    LV = []
    LH = []

    mp_X = defaultdict(int)
    mp_Y = defaultdict(int)

    mp_X[0] = 0
    mp_Y[0] = 0

    for _ in range(N):
        a,b,c = map(int, input().split())
        mp_X[a] = mp_X[b] = mp_Y[c] = 0
        LH.append((a,b,c))

    for _ in range(M):
        d,e,f = map(int, input().split())
        mp_X[d] = mp_Y[e] = mp_Y[f] = 0
        LV.append((e,f,d))

    sX = []
    sY = []

    for i, k in enumerate(sorted(mp_X)):
        mp_X[k] = i
        sX.append(k)
    for i, k in enumerate(sorted(mp_Y)):
        mp_Y[k] = i
        sY.append(k)

    sizeX = len(mp_X) * 2 - 1
    sizeY = len(mp_Y) * 2 - 1

    d = [[0 for _ in range(sizeY)] for _ in range(sizeX)]

    for x1,x2,y in LH:
        for x in range(mp_X[x1]*2, mp_X[x2]*2+1):
            d[x][mp_Y[y]*2] = -1

    for y1,y2,x in LV:
        for y in range(mp_Y[y1]*2, mp_Y[y2]*2+1):
            d[mp_X[x]*2][y] = -1

    dx = [0,1,0,-1]
    dy = [1,0,-1,0]

    q = []
    cx, cy = mp_X[0]*2, mp_Y[0]*2
    d[cx][cy] = 1
    q.insert(0, (cx,cy))
    while q:
        cx, cy = q.pop()
        for i in range(4):
            nx, ny = cx + dx[i], cy + dy[i]
            if 0 <= nx < sizeX and 0 <= ny < sizeY:
                if abs(d[nx][ny]) == 1:
                    continue

                d[nx][ny] = 1
                q.insert(0, (nx,ny))

    ans = 0
    for x in range(sizeX):

        if d[x][0] == 1 or d[x][sizeY-1] == 1:
            print("INF")
            break

        if x % 2 == 0:
            continue

        for y in range(sizeY):
            if d[0][y] == 1 or d[sizeX-1][y] == 1:
                print("INF")
                break
            if y % 2 == 0:
                continue
            if d[x][y] == 1:
                ans += (sX[x//2+1]-sX[x//2])*(sY[y//2+1]-sY[y//2])
        else:
            continue
        break
    else:
        print(ans)

main()