from collections import deque

def main():
    n, m = map(int, input().split())
    mapX = dict()
    mapY = dict()
    mapX["0"] = 0
    mapY["0"] = 0
    dx = [-1, 0, 1, 0]
    dy = [0, -1, 0, 1]
    lh = [None]*n
    lv = [None]*m
    for i in range(n):
        a, b, c = input().split()
        mapX[a], mapX[b], mapY[c] = 0, 0, 0
        lh[i] = [a, b, c]
    for i in range(m):
        d, e, f = input().split()
        mapX[d], mapY[e], mapY[f] = 0, 0, 0
        lv[i] = [f, e, d]
    xs, ys = [], []
    for k in mapX.keys():
        mapX[k] = len(xs)
        xs.append(k)
    for k in mapY.keys():
        mapY[k] = len(ys)
        ys.append(k)
    h = len(xs)*2
    w = len(ys)*2
    
    d = [[None]*w for _ in range(h)]
    for i in range(n):
        a, b, c = mapX[lh[i][0]]*2, mapX[lh[i][1]]*2, mapY[lh[i][2]]*2
        for x in range(a, b+1):
            d[x][c] = -1
    for i in range(m):
        a, b, c = mapY[lv[i][0]]*2, mapY[lv[i][1]]*2, mapX[lv[i][2]]*2
        for x in range(a, b+1):
            d[c][y] = -1
    q = deque()
    sx, sy = mapX["0"]*2, mapY["0"]*2
    d[sx][sy] = 1
    q.appendleft([sx, sy])
    while q:
        x, y = q.pop()
        for i in range(4):
            nx, ny = x+dx[i], y+dy[i]
            if nx < 0 or ny >= h:
                continue
            if ny < 0 or ny >= w:
                continue
            if d[nx][ny] != 0:
                continue
            d[nx][ny] = 1
            q.appendleft(nx, ny)
    ans = 0
    for x in range(h):
        for y in range(w):
            if d[x][y] != 1:
                continue
            if x*y == 0 or x == h-1 or y == w-1:
                print("INF")
                return
            if (x%2) * (y%2) == 0:
                continue
            ex = xs[x//2 + 1] - xs[x//2]
            ey = ys[y//2 + 1] - ys[y//2]
            ans += ex*ey
    print(ans)
    return
        
            
if __name__ == "__main__":
    main()