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

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

if wl > 0 or wh < 0 or hl > 0 or hh < 0:exit(print('INF'))  

wd = -wl+1
hd = -hl+1
wl = 1
wh += wd+1
hl = 1
hh += hd+1

map = [[0]*(wh+1) for _ in range(hh+1)]

for c,a,b in c_ab:
  a += hd
  b += hd
  c += wd
  if a < hl: a = hl
  if b > hh: b = hh
  for i in range(a,b+1):
    map[i][c] = 1

for d,e,f in d_ef:
  d += hd
  e += wd
  f += wd
  if e < wl: e = wl
  if f > wh: f = wh
  for i in range(e,f+1):
    map[d][i] = 1

dx = [2,0,-2,0]
dy = [0,2,0,-2]
map[hd+1][wd+1] = 9
que = deque([[wd+1,hd+1]])
cnt = 1
while que:
  x,y = que.popleft()
  for i in range(4):
    nx = x + dx[i]
    ny = y + dy[i]
    mx = x + dx[i]//2
    my = y + dy[i]//2
    
    if 0 < nx and nx <= wh+1 and 0 < ny and ny <= hh+1:
      if (nx == 1 and map[my][mx] != 1) or (ny == hh+1 and map[my][mx] != 1) or \
          (nx == wh+1 and map[my][mx] != 1) or (nx == hh+1 and map[my][mx] != 1):
        exit(print('INF'))
      elif map[ny][nx] == 0 and map[my][mx] != 1:
        map[ny][nx] = 2
        cnt += 1
        que.append([nx,ny])

print(cnt)
