from collections import deque
n,m = list(map(int, input().split()))
c_ab = []
d_ef = []
ab = deque([])
ef = deque([])
for i in range(n):
  A,B,C= list(map(int, input().split()))
  if A > B:
    t = A
    A = B
    B = t
  c_ab.append([C,A,B])

for i in range(m):
  D,E,F = list(map(int, input().split())) 
  if E > F:
    t = E
    E = F
    F = t
  d_ef.append([D,E,F])

c_ab.sort(key = lambda x:abs(x[0]))
d_ef.sort(key = lambda x:abs(x[0]))

wl = 0
wh = 0
for C,A,B in c_ab:
  wl = min(wl, C)
  wh = max(wh, C)
hl = 0
hh = 0
for D,E,F in d_ef:
  hl = min(hl, D)
  hh = max(hh, D)


hd= hl
wd = wl
wl = (wl-wd)*2
wh = (wh-wd)*2
hl = (hl-hd)*2
hh = (hh-hd)*2
start = [-wd*2, -hd*2]

map = [[0] * (hh+1) for _ in range(wh+1)]
for C,A,B in c_ab:
  C = (C-wd)*2
  A = (A-hd)*2
  B = (B-hd)*2
  if A < hl:A = hl
  if B > hh:B = hh
  for y in range(A,B+1):
    map[C][y] = 1
for D,E,F in d_ef:
  D = (D-hd)*2
  E = (E-wd)*2
  F = (F-wd)*2
  if E < wl:E = wl
  if F > wh:F = wh
  for x in range(E,F+1):
    map[x][D] = 1

dx = [1,0,-1,0]
dy = [0,1,0,-1]
que =deque([start])
cnt = 0
while que:
  x,y = que.popleft()
  for i in range(4):
    nx = x + dx[i]
    ny = y + dy[i]
    if (nx == 0 or nx == wh or ny == 0 or ny == hh) and map[nx][ny] == 0:
      exit(print('INF'))
    if 0 <= nx and nx <= wh and 0 <= ny and ny <= hh and map[nx][ny] == 0:
      cnt += 1
      map[nx][ny] = 1
      que.append([nx,ny])


print(cnt//2)