from collections import deque
n,m = list(map(int,input().split()))
CAB = [[0] * 3 for _ in range(n)]
DEF = [[0] * 3 for _ in range(m)]
wl, wh = 0,0
hl, hh = 0,0
for i in range(n):
  a,b,c = list(map(int,input().split()))
  if a > b:
    CAB[i][1] = b -1
    CAB[i][2] = a -1
  else:
    CAB[i][1] = a -1
    CAB[i][2] = b -1
  CAB[i][0] = c -1 
  wl = min(wl, c -1)
  wh = max(wh, c -1)
for i in range(m):
  d,e,f = list(map(int,input().split()))
  if e > f:
    DEF[i][1] = F -1
    DEF[i][2] = e -1
  else:
    DEF[i][1] = e -1
    DEF[i][2] = f -1
  DEF[i][0] = d -1
  hl = min(hl, d -1)
  hh = max(hh, d -1)

w = (wh - wl) * 2 +3
h = (hh - hl) * 2 +3

fen = [[0] * w for _ in range(h)]
dp= [[0] * w for _ in range(h)]

for i in range(n):
  a = (CAB[i][1] - hl) *2 +1
  b = (CAB[i][2] - hl) *2 +1
  c = (CAB[i][0] - wl) *2 +1
  b = min(b, h-1)
  for j in range(a,b+1):
    fen[j][c] = 1
for i in range(m):
  e = (DEF[i][1] - wl) *2 +1
  f = (DEF[i][2] - wl) *2 +1
  d = (DEF[i][0] - hl) *2 +1
  f = min(f, w-1)
  for j in range(e,f+1):
    fen[d][j] = 1

que = deque([[-hl*2, -wl*2]])
dx = [2,0,-2,0]
dy = [0,2,0,-2]

fen[-hl*2][-wl*2] = 2
ans = 0
while que:
  x,y = que.popleft()
  for i in range(4):
    dxi = dx[i]
    dyi = dy[i]
    nx = x + dxi
    ny = y + dyi
    fx = x + dxi//2
    fy = y + dyi//2
    if 0 <= nx and nx <= w and 0 <= ny and ny <= h:
      nf = fen[fy][fx]
      nd = dp[ny][nx]
      if (nx == 0 or nx == w or ny == 0 or ny == h) and nf != 1:
        exit(print('INF'))
      if nd == 0 and nf != 1:
        dp[ny][nx] = 1
        ans += 1
        que.append([ny,nx])

print(ans)
