### BUGGY CODE ###

n, m = map(int, input().split())
NS = []
X_num = set()
EW = []
Y_num = set()

INF = 10 ** 36

X_num.add(INF)
X_num.add(0)
X_num.add(-INF)
Y_num.add(INF)
Y_num.add(0)
Y_num.add(-INF)

cant_inc_x = [[0] * 3300 for i in range(3300)]
cant_inc_y = [[0] * 3300 for i in range(3300)]

for i in range(n):
    a, b, c = map(int, input().split())
    X_num.add(a)
    X_num.add(b)
    Y_num.add(c)
    NS.append((a,b,c))

for i in range(m):
    d, e, f = map(int, input().split())
    X_num.add(d)
    Y_num.add(e)
    Y_num.add(f)
    EW.append((d,e,f))

X_dict = {}
Y_dict = {}

X_num = sorted(list(X_num))
Y_num = sorted(list(Y_num))


for xp, x in enumerate(X_num):
    X_dict[x] = xp
    xp += 1

for yp, y in enumerate(Y_num):
    Y_dict[y] = yp
    yp += 1

#(a,b) (a,c)
for a, b, c in NS:
    a = X_dict[a]
    b = X_dict[b]
    c = Y_dict[c]
    cant_inc_y[a][c-1] += 1
    cant_inc_y[b][c-1] -= 1
    

#(d,e) (d,f)
for d, e, f in EW:
    d = X_dict[d]
    e = Y_dict[e]
    f = Y_dict[f]
    cant_inc_x[d-1][e] += 1
    cant_inc_x[d-1][f] -= 1

for i in range(3003):
    for j in range(3003):
        if(j):cant_inc_x[i][j] += cant_inc_x[i][j-1]
        if(i):cant_inc_y[i][j] += cant_inc_y[i-1][j]

from collections import deque
q = deque()
q.append((X_dict[0], Y_dict[0]))
done = [[False] * 3003 for _ in range(3003)]

ans = 0


while len(q) != 0:
    (nowx, nowy) = q.pop()
    if nowx < 0 or nowy < 0 or nowx+1 >= len(X_num) or nowy+1 >= len(Y_num):
        continue
    if done[nowx][nowy]:continue
    done[nowx][nowy] = True
    ans += (X_num[nowx+1] - X_num[nowx]) * (Y_num[nowy+1] - Y_num[nowy])
    if ans > INF:
      print("INF")
      exit()
    if cant_inc_x[nowx][nowy] == 0:q.append((nowx+1, nowy))
    if cant_inc_y[nowx][nowy] == 0:q.append((nowx, nowy+1))
    if nowx > 0 and cant_inc_x[nowx-1][nowy] == 0:q.append((nowx-1, nowy))
    if nowy > 0 and cant_inc_y[nowx][nowy-1] == 0:q.append((nowx, nowy-1))

print(ans)


### FIXED CODE ###

from collections import deque
import bisect

INF = float("inf")

N,M = map(int,input().split())

xtic = {0,-INF,INF}
ytic = {0,-INF,INF}

hor = []
for _ in range(N):
  a,b,c = map(int,input().split())
  hor.append((c,a,b))
  xtic.add(a)
  xtic.add(b)
  ytic.add(c)
  
ver = []
for _ in range(M):
  d,e,f = map(int,input().split())
  ver.append((d,e,f))
  xtic.add(d)
  ytic.add(e)
  ytic.add(f)

xtic = list(xtic)
ytic = list(ytic)
xtic.sort()
ytic.sort()
xdic = {xtic[i]:i+1 for i in range(len(xtic))}
ydic = {ytic[i]:i+1 for i in range(len(ytic))}

gyaku_xdic = {xdic[k]:k for k in xdic}
gyaku_ydic = {ydic[k]:k for k in ydic}

hor.sort()
ver.sort()

hor_dic = {}
ver_dic = {}

now = None
for c,a,b in hor:
  c,a,b = ydic[c],xdic[a],xdic[b]
  if c != now:
    hor_dic[c] = (1<<b) - (1<<a)
  else:
    hor_dic[c] |= (1<<b) - (1<<a)
  now = c

now = None
for d,e,f in ver:
  d,e,f = xdic[d],ydic[e],ydic[f]
  if d != now:
    ver_dic[d] = (1<<f) - (1<<e)
  else:
    ver_dic[d] |= (1<<f) - (1<<e)
  now = d

def is_connected(x,y,dx,dy):
  if dx == 0:
    if dy > 0:
      if (hor_wall[y+1]>>x)&1:
        return False
      return True
    else:
      if (hor_wall[y]>>x)&1:
        return False
      return True
  else:
    if dx > 0:
      if (ver_wall[x+1]>>y)&1:
        return False
      return True
    else:
      if (ver_wall[x]>>y)&1:
        return False
      return True
      
def calc_area(x,y):
  X = gyaku_xdic[x+1] - gyaku_xdic[x]
  Y = gyaku_ydic[y+1] - gyaku_ydic[y]
  return X*Y

offset = [(1,0),(0,1),(-1,0),(0,-1)]
x0 = bisect.bisect(xtic,0)
y0 = bisect.bisect(ytic,0)
W,H = len(xtic)+1 ,len(ytic)+1

hor_wall = [0 for i in range(H)]
ver_wall = [0 for i in range(W)]

for k in hor_dic:
  hor_wall[k] = hor_dic[k]
for k in ver_dic:
  ver_wall[k] = ver_dic[k]
"""
for k in range(H):
  listb = list(map(int,list(bin(hor_wall[k])[2:])))
  hor_wall[k] = [0 for j in range(H-len(listb))] + listb

for k in range(W):
  listb = list(map(int,list(bin(ver_wall[k])[2:])))
  ver_wall[k] = [0 for j in range(W-len(listb))] + listb  
"""

d = [[0 for i in range(W)] for j in range(H)]
d[y0][x0] = 1
q = deque([(x0,y0)])

area = 0

while q:
  x,y = q.pop()
  area += calc_area(x,y)
  for dx,dy in offset:
    nx,ny = x+dx,y+dy
    if 0<=nx<W and 0<=ny<H:
      if is_connected(x,y,dx,dy):
        if nx == 0 or ny == 0 or nx == W-1 or ny == H-1:
          print("INF")
          exit()
        if d[ny][nx] == 0:
          d[ny][nx] = 1
          q.append((nx,ny))

print(area)