import sys
N, M = map(int, input().split())
X = []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((a,b,c))
Y = []
for _ in range(M):
    a, b, c = map(int, input().split())
    Y.append((b, c, a))
X.sort(key=lambda x:x[2])
Y.sort(key=lambda x:x[2])

#print(X)
#print(Y)
dxs = []
bc = X[0][2]
for _, _, c in X[1:]:
    dxs.append(c-bc)
    bc = c
dys = []
bc = Y[0][2]
for _, _, c in Y[1:]:
    dys.append(c-bc)
    bc = c
#print(dxs, dys)
Ws = set()
for i, (a, b, c) in enumerate(X):
    yi = 0
    for (x1, y1, z1), (x2, y2, z2) in zip(Y, Y[1:]):
        if a<=z1 and z2<=b:
            Ws.add(((i-1, yi), (i, yi)))
            Ws.add(((i, yi), (i-1, yi)))
        yi += 1

for i, (a, b, c) in enumerate(Y):
    yi = 0
    for (x1, y1, z1), (x2, y2, z2) in zip(X, X[1:]):
        if a<=z1 and z2<=b:
            Ws.add(((yi, i-1), (yi, i)))
            Ws.add(((yi, i), (yi, i-1)))
        yi += 1
#print(Ws)

fci = -1
for _, _, c in X:
    if 0<c:
        break
    fci += 1
if fci < 0 or N-1<=fci:
    print("INF")
    sys.exit()
fcj = -1
for _, _, c in Y:
    if 0<c:
        break
    fcj += 1
if fcj < 0 or M-1<=fcj:
    print("INF")
    sys.exit()
#print(fci, fcj)
stack = [(fci, fcj)]
S = 0
vs = set([(fci, fcj)])
while stack:
    i,j = stack.pop()
    S += dxs[i]*dys[j]
    for k, l in [(i+1, j), (i-1, j), (i, j-1), (i, j+1)]:
        if ((i, j), (k, l)) in Ws:
            continue
#        print(k, l)
        if k<0 or N-2<k:
            print("INF")
            sys.exit()
        if l<0 or M-2<l:
            print("INF")
            sys.exit()
        if (k, l) in vs:
            continue
        vs.add((k, l))
        stack.append((k, l))
print(S)
