from collections import deque
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
a = [0]*n
b = [0]*n
c = [0]*n
d = [0]*m
e = [0]*m
f = [0]*m

for i in range(n):
    a[i], b[i], c[i] = map(int, input().split())
for i in range(m):
    d[i], e[i], f[i] = map(int, input().split())

x_items = list(set(a+b+d+[0]))
y_items = list(set(c+e+f+[0]))

x_items.sort()
y_items.sort()
xi = 0
yi = 0
x_map = {}
y_map = {}
for i in x_items:
    x_map[i] = xi
    xi = xi + 1
for i in y_items:
    y_map[i] = yi
    yi = yi + 1


h = len(x_map)*2
w = len(y_map)*2
grid = [[0] * w for i in range(h)]
for i in range(n):
    a_comp = x_map[a[i]]*2
    b_comp = x_map[b[i]]*2
    c_comp = y_map[c[i]]*2
    for x in range(a_comp,b_comp+1):
        grid[x][c_comp] = 2

for i in range(m):
    d_comp = x_map[d[i]]*2
    e_comp = y_map[e[i]]*2
    f_comp = y_map[f[i]]*2
    for y in range(e_comp,f_comp+1):
        grid[d_comp][y] = 2

q = deque()
xo = x_map[0]*2
yo = y_map[0]*2
dx = (-1, 0, 1, 0)
dy = (0,-1,0,1)
q.append((xo,yo))
flug1 = True

grid[xo][yo] = 1
ans = 0
while q:
    x, y = q.popleft()
    if x%2 != 0 and y%2 != 0:
        xx = x_items[x//2+1] - x_items[x//2]
        yy = y_items[y//2+1] - y_items[y//2]
        ans = ans + xx*yy
    for i in range(4): 
        nx = x+dx[i]
        ny = y+dy[i]
        if nx < 0 or nx >= h:
            flug1 = False
            break
        if ny < 0 or ny >= w:
            flug1 = False
            break
        if grid[x+dx[i]][y+dy[i]] == 0:
            grid[x+dx[i]][y+dy[i]] = 1
            q.append((x+dx[i],y+dy[i]))
    if flug1 == False:
        ans = "INF"
        break

print(ans)