# F - . (Single Dot)

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

N, M = map(int, readline().split())
INF = 2 * 10**9 + 1
W = defaultdict(int)

min_y = INF
max_y = INF * -1
for i in range(N):
    A, B, C = map(int, readline().split())
    A *= 2
    B *= 2
    C *= 2
    min_y = min(min_y, C)
    max_y = max(max_y, C)
    for j in range(A, B+1):
        W[(j, C)] = -1

min_x = INF
max_x = INF * -1
for i in range(M):
    D, E, F = map(int, readline().split())
    D *= 2
    E *= 2
    F *= 2
    min_x = min(min_x, D)
    max_x = max(max_x, D)
    for j in range(E, F+1):
        W[(D, j)] = -1

q = deque()
q.append((0, 0))
W[(0, 0)] = -1
ans = 0
b_ans = True
while len(q) > 0:
    x, y = q.pop()
    #print(x, y)
    if x > max_x or x < min_x or y > max_y or y < min_y:
        b_ans = False
        break
    for (vx, vy) in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
        nx = x + vx
        ny = y + vy
        if (nx, ny) not in W:
            if nx%2==1 and ny%2==1:
                ans += 1
            q.append((nx, ny))
            W[(nx, ny)] = -1

if b_ans == True:
    print(ans)
else:
    print('INF')
