# Original solution
import sys
input = sys.stdin.buffer.readline
from collections import deque

N, M = list(map(int, input().split()))
abcs = [tuple(map(int, input().split())) for _ in range(N)]
defs = [tuple(map(int, input().split())) for _ in range(M)]


xs = set([0])
ys = set([0])
for a, b, c in abcs:
    xs.add(a)
    xs.add(b)
    ys.add(c)
for d, e, f in defs:
    xs.add(d)
    ys.add(e)
    ys.add(f)

scatter_x = sorted(xs)
scatter_y = sorted(ys)

gather_x = {e:i for i, e in enumerate(scatter_x)}
gather_y = {e:i for i, e in enumerate(scatter_y)}

x_size = 2 * len(scatter_x)
y_size = 2 * len(scatter_y)

field = [[True] * y_size for _ in range(x_size)]

for a, b, c in abcs:
    y = 2 * gather_y[c]
    for x in range(2 * gather_x[a], 2 * gather_x[b] + 1):
        field[x][y] = False

for d, e, f in defs:
    x = 2 * gather_x[d]
    for y in range(2 * gather_y[e], 2 * gather_y[f] + 1):
        field[x][y] = False


area = 0
sx = gather_x[0] * 2
sy = gather_y[0] * 2
field[sx][sy] = False
stack = deque([(sx, sy)])
while stack:
    x, y = stack.pop()
    for dx, dy in ((0, 1), (1, 0), (0, -1), (-1, 0)):
        if not (0 <= x+dx < x_size and 0 <= y+dy < y_size):
            print("INF")
            exit()
        else:
            if field[x+dx][y+dy]:
                stack.append( (x+dx, y+dy) )
                field[x+dx][y+dy] = False

    if x % 2 == 1 and y % 2 == 1:
        if x == x_size - 1 and y == y_size - 1:
            print("INF")
            exit()
        else:
            delta_x = scatter_x[x//2 + 1] - scatter_x[x//2]
            delta_y = scatter_y[y//2 + 1] - scatter_y[y//2]       
            area += delta_x * delta_y

print(area)


# Optimized solution
import sys
input = sys.stdin.buffer.readline

N, M = list(map(int, input().split()))
abcs = [tuple(map(int, input().split())) for _ in range(N)]
defs = [tuple(map(int, input().split())) for _ in range(M)]


xs = set([0])
ys = set([0])
for a, b, c in abcs:
    xs.add(a)
    xs.add(b)
    ys.add(c)
for d, e, f in defs:
    xs.add(d)
    ys.add(e)
    ys.add(f)

scatter_x = [-10**9-2] + sorted(xs)
scatter_y = [-10**9-2] + sorted(ys)

gather_x = {e:i for i, e in enumerate(scatter_x)}
gather_y = {e:i for i, e in enumerate(scatter_y)}

x_size = 2 * len(scatter_x)
y_size = 2 * len(scatter_y)

field = [[True] * y_size for _ in range(x_size)]

for a, b, c in abcs:
    y = 2 * gather_y[c]
    for x in range(2 * gather_x[a], 2 * gather_x[b] + 1):
        field[x][y] = False

for d, e, f in defs:
    x = 2 * gather_x[d]
    for y in range(2 * gather_y[e], 2 * gather_y[f] + 1):
        field[x][y] = False

#print(*[''.join(map(lambda c: '.' if c else '#', row)) for row in field], sep = '\n')

area = 0
sx = gather_x[0] * 2 + 1
sy = gather_y[0] * 2 + 1
field[sx][sy] = False
stack_x = [sx]
stack_y = [sy]
while stack_x:
    x = stack_x.pop()
    y = stack_y.pop()
    if x == 1 or y == 1 or x == x_size-1 or y == y_size-1:
        print("INF")
        exit()
    
    if field[x+1][y] and field[x+2][y]:
        stack_x.append(x+2)
        stack_y.append(y)
        field[x+2][y] = False
    if field[x][y+1] and field[x][y+2]:
        stack_x.append(x)
        stack_y.append(y+2)
        field[x][y+2] = False
    if field[x-1][y] and field[x-2][y]:
        stack_x.append(x-2)
        stack_y.append(y)
        field[x-2][y] = False
    if field[x][y-1] and field[x][y-2]:
        stack_x.append(x)
        stack_y.append(y-2)
        field[x][y-2] = False

    delta_x = scatter_x[x//2 + 1] - scatter_x[x//2]
    delta_y = scatter_y[y//2 + 1] - scatter_y[y//2]       
    area += delta_x * delta_y

    #print(*[''.join(map(lambda c: '.' if c else '#', row)) for row in field], sep = '\n')

print(area)