N, M = map(int, input().split())
A, B, C = [], [], []
for _ in range(N):
  a, b, c = map(int, input().split())
  A.append(a)
  B.append(b)
  C.append(c)
D, E, F = [], [], []
for _ in range(M):
  d, e, f = map(int, input().split())
  D.append(d)
  E.append(e)
  F.append(f)

orig_X = sorted(set([0] + D))
orig_Y = sorted(set([0] + C))
                
X = {x: i for i, x in enumerate(orig_X)}
Y = {y: i for i, y in enumerate(orig_Y)}
max_X = len(X) - 1
max_Y = len(Y) - 1
#print(X, Y)

movable = [(-1, 0), (1, 0), (0, -1), (0, 1)]
blocked = {}
# (x, y) -> stands at (x+0.5, y+0.5)
for a, b, c in zip(A, B, C):
  y = Y[c]
  Xa = -1
  Xb = -1
  for i, x in enumerate(orig_X):
    if Xa < 0 and x >= a:
      Xa = i
    if x > b:
      break
    Xb = i
  #for x in range(X[a], X[b]):
  for x in range(Xa, Xb):
    if y < max_Y:
      if (x, y) not in blocked:
        blocked[(x, y)] = set()
      blocked[(x, y)].add((0, -1))
    if y > 0:
      if (x, y-1) not in blocked:
        blocked[(x, y-1)] = set()
      blocked[(x, y-1)].add((0, +1))

for d, e, f in zip(D, E, F):
  x = X[d]
  Ye = -1
  Yf = -1
  for i, y in enumerate(orig_Y):
    if Ye < 0 and y >= e:
      Ye = i
    if y > f:
      break
    Yf = i
  # for y in range(Y[e], Y[f]):
  for y in range(Ye, Yf):
    if (x, y) not in blocked:
      blocked[(x, y)] = set()
    blocked[(x, y)].add((-1, 0))
    if x > 0:
      if (x-1, y) not in blocked:
        blocked[(x-1, y)] = set()
      blocked[(x-1, y)].add((+1, 0))

#print(sorted(blocked))

visited = [0] * max_X * max_Y
def get_visited(x, y):
  return visited[x * max_Y + y]
def set_visited(x, y):
  #print(x,y)
  visited[x * max_Y + y] = True

to_visit = [(X[0], Y[0])]
while to_visit:
  #print(to_visit)
  x, y = to_visit.pop()
  if x < 0 or x >= max_X or y < 0 or y >= max_Y:
    print('INF')
    exit()
  if get_visited(x, y):
    continue
  set_visited(x, y)
  for d in movable:
    if (x, y) in blocked and d in blocked[(x, y)]:
      continue
    to_visit.append((x + d[0], y + d[1]))

ans = 0
for x in range(0, max_X):
  for y in range(0, max_Y):
    if get_visited(x, y):
      ans += (orig_X[x+1] - orig_X[x]) * (
        orig_Y[y+1] - orig_Y[y])
print(ans)