from collections import deque
from itertools import product
import sys
n, m = map(int, input().split())
vertical = list()
horizontal = list()
for _ in range(n):
  a, b, c = map(int, input().split())
  vertical.append((a, b, c))
for _ in range(m):
  d, e, f = map(int, input().split())
  horizontal.append((d, e, f))
leftmost = sys.maxsize
rightmost = -sys.maxsize
for segment in vertical:
  leftmost = min(segment[2], leftmost)
  rightmost = max(segment[2], rightmost)
upmost = sys.maxsize
downmost = -sys.maxsize
for segment in horizontal:
  upmost = min(segment[0], upmost)
  downmost = max(segment[0], downmost)
# maybe bfs... integer grid may be too fine.
stack_positions = deque()
covered_positions = set()
# true position is -0.5, -0.5 of this
initial_range = [0, 1]
for d, r in product(initial_range, initial_range):
  stack_positions.append((d, r))
  covered_positions.add((d, r))
area = 4
d, r = 0, 0
while upmost-3<=d<=downmost and leftmost-3<=r<=3+rightmost and stack_positions:
  d, r = stack_positions.popleft()
  can_go_right = True
  can_go_left = True
  can_go_up = True
  can_go_down = True
  for segment in vertical:
    if r == segment[2]:
      if segment[0]<d<=segment[1]: can_go_right = False
    elif r == segment[2]+1:
      if segment[0]<d<=segment[1]: can_go_left = False
  for segment in horizontal:
    if d == segment[0]:
      if segment[1]<r<=segment[2]: can_go_down = False
    elif d == segment[0]+1:
      if segment[1]<r<=segment[2]: can_go_up = False
  can_go_right = can_go_right and not (r+1, d) in covered_positions
  can_go_left = can_go_left and not (r-1, d) in covered_positions
  can_go_down = can_go_down and not (r, d+1) in covered_positions
  can_go_up = can_go_up and not (r, d-1) in covered_positions
  if can_go_right:
    area += 1
    stack_positions.append((r+1, d))
    covered_positions.add((r+1, d))
  if can_go_left:
    area += 1
    stack_positions.append((r-1, d))
    covered_positions.add((r-1, d))
  if can_go_up:
    area += 1
    stack_positions.append((r, d-1))
    covered_positions.add((r, d-1))
  if can_go_down:
    area += 1
    stack_positions.append((r, d+1))
    covered_positions.add((r, d+1))
if not stack_positions:
  print(area)
else:
  print("INF")