output_description: If the area of the region the cow can reach is infinite, print `INF`;
  otherwise, print an integer representing the area in \mathrm{cm^2}.
  
  (Under the constraints, it can be proved that the area of the region is always
  an integer if it is not infinite.)
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N M
      A_1 B_1 C_1
      :
      A_N B_N C_N
      D_1 E_1 F_1
      :
      D_M E_M F_M
attempt: # coding: utf-8
  import sys
  
  # from operator import itemgetter
  sysread = sys.stdin.readline
  read = sys.stdin.read
  from heapq import heappop, heappush
  
  # from collections import defaultdict
  sys.setrecursionlimit(10**7)
  
  
  # import math
  # from itertools import product#accumulate, combinations, product
  # import bisect# lower_bound etc
  # import numpy as np
  # from copy import deepcopy
  # from collections import deque
  def run():
      N, M = map(int, sysread().split())
      verticals = []
      for i in range(N):
          verticals.append(list(map(int, sysread().split())))
      horizontals = []
  
      for i in range(M):
          horizontals.append(list(map(int, sysread().split())))
  
      verticals.sort(key=lambda x: x[2])
      horizontals.sort(key=lambda x: x[0])
  
      to = [[] for _ in range(N * M)]
      for xi, (a, b, c) in enumerate(verticals):
          pre = None
          for yi, (d, e, f) in enumerate(horizontals):
              if a <= d and d <= b and e <= c and c <= f:
                  cur = [xi * M + yi, d]  # (id, d)
                  if pre == None:
                      pre = cur[:]
                      continue
                  to[pre[0]].append((cur[0], cur[1] - pre[1], c))  # Use Green's
                  to[cur[0]].append((pre[0], -cur[1] + pre[1], c))
                  pre = cur[:]
  
      for yi, (d, e, f) in enumerate(horizontals):
          pre = None
          for xi, (a, b, c) in enumerate(verticals):
              if a <= d and d <= b and e <= c and c <= f:
                  cur = [xi * M + yi, c]  # (id, c)
                  if pre == None:
                      pre = cur[:]
                      continue
                  to[pre[0]].append((cur[0], 0, c))
                  to[cur[0]].append((pre[0], 0, c))
                  pre = cur[:]
  
      seen = [False] * (N * M)
      INF = float("inf")
      min_sq = INF
      for i in range(N * M):
          stack = []
          goal = -1
          if not seen[i] and len(to[i]) > 0:
              heappush(stack, (0, i))  # (sq, node)
  
          while stack:
              sq, current = heappop(stack)
              seen[current] = True
              for next, dist, y in to[current]:
                  if next == i:
                      goal = 1
                      sq += dist * y
                      break
                  if not seen[next]:
                      heappush(stack, (sq + dist * y, next))
          if goal == 1:
              min_sq = min(min_sq, sq)
  
      if min_sq == INF:
          print("INF")
      else:
          print(min_sq)
  
  
  if __name__ == "__main__":
      run()
  
problem_description: Statement
  
  There is a grass field that stretches infinitely.
  
  In this field, there is a negligibly small cow. Let (x, y) denote the point
  that is x\ \mathrm{cm} south and y\ \mathrm{cm} east of the point where the
  cow stands now. The cow itself is standing at (0, 0).
  
  There are also N north-south lines and M east-west lines drawn on the field.
  The i-th north-south line is the segment connecting the points (A_i, C_i) and
  (B_i, C_i), and the j-th east-west line is the segment connecting the points
  (D_j, E_j) and (D_j, F_j).
  
  What is the area of the region the cow can reach when it can move around as
  long as it does not cross the segments (including the endpoints)? If this area
  is infinite, print `INF` instead.
samples: [{"input": "5 6\n    1 2 0\n    0 1 1\n    0 2 2\n    -3 4 -1\n    -2 6 3\n    1 0 1\n    0 1 2\n    2 0 2\n    -1 -4 5\n    3 -2 4\n    1 2 4", "output": "13\n    \n\nThe area of the region the cow can reach is 13\\ \\mathrm{cm^2}.\n\n![Sample 1](https://img.atcoder.jp/abc168/education.png)\n\n* * *"}, {"input": "6 1\n    -3 -1 -2\n    -3 -1 1\n    -2 -1 2\n    1 4 -2\n    1 4 -1\n    1 4 1\n    3 1 4", "output": "INF\n    \n\nThe area of the region the cow can reach is infinite."}]