n,m = map(int,input().split())
ABC = [list(map(int,input().split())) for i in range(n)]
DEF = [list(map(int,input().split())) for i in range(m)]
xset = set([0])
yset = set([0])
for a,b,c in ABC:
  xset.add(a)
  xset.add(b)
  yset.add(c)
for d,e,f in DEF:
  xset.add(d)
  yset.add(e)
  yset.add(f)
xls = list(xset)
yls = list(yset)
xls.sort()
yls.sort()
dcx = {xls[i]:i for i in range(len(xls))}
dcy = {yls[i]:i for i in range(len(yls))}
xmax = len(xls)+1
ymax = len(yls)+1
banned = set()
for a,b,c in ABC:
  da,db,dc = dcx[a],dcx[b],dcy[c]
  for i in range(da,db):
    banned.add((i*xmax+dc-1,i*xmax+dc))
for d,e,f in DEF:
  dd,de,df = dcx[d],dcy[e],dcy[f]
  for i in range(de,df):
    banned.add(((dd-1)*xmax+i,dd*xmax+i))
sx,sy = dcx[0],dcy[0]
graph = [[] for i in range((xmax*ymax+1))]
for i in range(xmax):
  for j in range(ymax):
    for dx,dy in (1,0),(0,1),(-1,0),(0,-1):
      if 0 <= i+dx <= xmax-1 and 0 <= j+dy <= ymax-1:
        nx,ny = i+dx,j+dy
        if (i*xmax+j,nx*xmax+ny) not in banned and (nx*xmax+ny,i*xmax+j) not in banned:
          graph[i*xmax+j].append(nx*xmax+ny)

grid = [0 for i in range(xmax*ymax+1)]
stack = [sx*xmax+sy]
while stack:
  x = stack.pop()
  if grid[x] == 0:
    grid[x] = 1
  for y in graph[x]:
    if grid[y] == 0:
      grid[y] = 1
      stack.append(y)
if grid.count(1) >= xmax*ymax:
  print("INF")
  exit()

ans = 0
for i in range(xmax):
  for j in range(ymax):
    if grid[i*xmax+j] == 1:
      ans += (xls[i+1]-xls[i])*(yls[j+1]-yls[j])
print(ans)