import numpy as np

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

    mapX = dict()
    mapY = dict()

    lh = []
    lw = []
    for i in range(area):
        if i <= N-1:
            a, b, c = map(int, input().split())
            mapX[a] = 0
            mapX[b] = 0
            mapY[c] = 0
            lh.append({'a':a, 'b':b, 'c':c})
        else:
            c, a, b = map(int, input().split())
            mapY[a] = 0
            mapY[b] = 0
            mapX[c] = 0
            lw.append({'a':a, 'b':b, 'c':c})

    mapXs = dict(sorted(mapX.items()))
    mapYs = dict(sorted(mapY.items()))

    xg = list()
    yg = list()

    for k in mapXs:
        mapXs[k] = len(xg)
        xg.append(k)

    for k in mapYs:
        mapYs[k] = len(yg)
        yg.append(k)

    #print(str(xg), '\n', str(yg))

    h = len(xg)*2
    w = len(yg)*2

    grid = np.zeros((h,w), int)

    for i in range(N):
        a = mapXs[lh[i]['a']]*2
        b = mapXs[lh[i]['b']]*2
        c = mapYs[lh[i]['c']]*2
        for j in range(a,b+1): grid[j][c] = -1

    for i in range(M):
        a = mapYs[lw[i]['a']]*2
        b = mapYs[lw[i]['b']]*2
        c = mapXs[lw[i]['c']]*2
        for j in range(a,b+1): grid[c][j] = -1

    #print('befor BFS\n', str(grid))

    que = dict()
    cdX = mapXs[next(iter(mapXs))]*2
    cdY = mapYs[next(iter(mapYs))]*2

    grid[cdX][cdY] = 1
    que = [[cdX,cdY]]

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

    while len(que) != 0:
        q = que.pop(0)
        for i in range(4):
            currentX = q[0]+dx[i]
            currentY = q[1]+dy[i]
            if currentX < 0 or currentX >= h: continue
            if currentY < 0 or currentY >= w: continue
            if grid[currentX][currentY] != 0: continue

            grid[currentX][currentY]=1
            que.append([currentX,currentY])

    #print('after BFS\n', str(grid))

    ans = 0
    for x in range(h):
        for y in range(w):
            if grid[x][y] != 1: continue
            if x%2 == 0 or y%2 == 0: continue
            if (x == 0 or x == h-1) or (y == 0 or y == w-1):
                print('INF')
                return
            
            ans += (xg[x%2+1]-xg[x%2])*(yg[y%2+1]-yg[y%2])

    print(ans)

if __name__=='__main__':
    main()