from bisect import bisect_left, bisect_right
from collections import defaultdict, deque
inpl = lambda: list(map(int,input().split()))
N, M = inpl()
hlines_orig = []
Xgrid = set()
vlines_orig = []
Ygrid = set()
for _ in range(N):
    A, B, C = inpl()
    hlines_orig.append((A,B,C))
    Ygrid.add(C)
for _ in range(M):
    D, E, F = inpl()
    vlines_orig.append((D,E,F))
    Xgrid.add(D)

Xgrid = sorted(list(Xgrid))
Ygrid = sorted(list(Ygrid))
W = len(Xgrid)
H = len(Ygrid)
areas = [[(Xgrid[w+1]-Xgrid[w])*(Ygrid[h+1]-Ygrid[h]) for h in range(H-1)] for w in range(W-1)]
walled = defaultdict(bool)
dirs = {(0,1),(1,0),(-1,0),(0,-1)}
for A, B, C in hlines_orig:
    a = bisect_right(Xgrid, A) - 1
    b = bisect_right(Xgrid, B) - 1
    c = bisect_right(Ygrid, C) - 1
    for i in range(a, b):
        if c < H-1:
            walled[((i,c),(0,-1))] = True
        if c > 0:
            walled[((i,c-1),(0,1))] = True

for D, E, F in vlines_orig:
    d = bisect_right(Ygrid, D) - 1 
    e = bisect_right(Xgrid, E) - 1 
    f = bisect_right(Xgrid, F) - 1
    for i in range(e, f):
        if d < W-1:
            walled[((d,i),(-1,0))] = True
        if d > 0:
            walled[((d-1,i),(1,0))] = True

x, y = bisect_right(Xgrid, 0) - 1, bisect_right(Ygrid, 0) - 1
if x == 0 or y == 0 or x >= W-1 or y >= H-1:
    print('INF')
    exit()
else:
    x -= 1
    y -= 1
visited = [[ False for _ in range(H-1) ] for _ in range(W-1)]
visited[x][y] = True
pool = deque([(x,y)])
ans = 0
while pool:
    x, y = pool.popleft()
    ans += areas[x][y]
    for d in dirs:
        if not walled[((x,y),d)]:
            cx, cy = x+d[0], y+d[1]
            if cx < 0 or cx >= W-1 or cy < 0 or cy >= H-1:
                print('INF')
                exit()
            elif not visited[cx][cy]:
                visited[cx][cy] = True
                pool.append((cx,cy))
print(ans)
