N, M = map(int, input().split())
A, B, X, Y = [], [], {-10**9-1, 0, 10**9+1}, {-10**9-1, 0, 10**9+1}
for _ in range(N):
    a, b, c = map(int, input().split())
    A.append((a, b, c))
    X.add(a)
    X.add(b)
    Y.add(c)
for _ in range(M):
    d, e, f = map(int, input().split())
    B.append((d, e, f))
    X.add(d)
    Y.add(e)
    Y.add(f)
X = sorted(list(X))
Y = sorted(list(Y))
S = {a:i for i, a in enumerate(X)}
T = {a:i for i, a in enumerate(Y)}
H = len(X)
W = len(Y)
Z1 = [[0] * W for _ in range(H)]
Z2 = [[0] * W for _ in range(H)]

for a, b, c in A:
    a, b, c = S[a], S[b], T[c]
    for i in range(a, b):
        Z1[i][c] = 1
for d, e, f in B:
    d, e, f = S[d], T[e], T[f]
    for j in range(e, f):
        Z2[d][j] = 1

s = S[0] * W + T[0]

from collections import deque

def BFS(i0=0):
    Q = deque([i0])
    D = [-1] * (H * W)
    D[i0] = 0
    ans = (X[S[0]+1] - X[S[0]]) * (Y[T[0]+1] - Y[T[0]])
    while Q:
        x = Q.popleft()
        i, j = x // W, x % W
        dd = []
        if Z1[i][j] == 0: dd.append((0, -1))
        if Z1[i][j+1] == 0: dd.append((0, 1))
        if Z2[i][j] == 0: dd.append((-1, 0))
        if Z2[i+1][j] == 0: dd.append((1, 0))
        for di, dj in dd:
            ni, nj = i + di, j + dj
            if not (0 < ni < H - 1 and 0 < nj < W - 1):
                print("INF")
                exit()
            y = ni * W + nj
            if D[y] == -1:
                D[y] = D[x] + 1
                ans += (X[ni+1] - X[ni]) * (Y[nj+1] - Y[nj])
                Q.append(y)
    return ans
bfs = BFS(s)
print(bfs)