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: #!/usr/bin/env python
  # -*- coding: utf-8 -*-
  import bisect
  import collections
  
  
  class VBoarder(object):
  
      def __init__(self, x1, x2, y):
          self.x1 = x1
          self.x2 = x2
          self.y = y
  
  
  class HBoarder(object):
  
      def __init__(self, x, y1, y2):
          self.x = x
          self.y1 = y1
          self.y2 = y2
  
  
  class Cell(object):
  
      def __init__(self, x1, y1, x2, y2):
          self.x1 = x1
          self.y1 = y1
          self.x2 = x2
          self.y2 = y2
          self.up = True
          self.down = True
          self.left = True
          self.right = True
          self.checked = False
  
      def area(self):
          return (self.x2 - self.x1) * (self.y2 - self.y1)
  
      def __str__(self):
          return "(({:2d},{:2d}),({:2d},{:2d})){}{}{}{}".format(
              self.x1,
              self.y1,
              self.x2,
              self.y2,
              "Uu"[int(self.up)],
              "Dd"[int(self.down)],
              "Ll"[int(self.left)],
              "Rr"[int(self.right)],
          )
  
  
  def main():
      N, M = map(int, input().split())
      vborders = [VBoarder(*map(int, input().split())) for _ in range(N)]
      hborders = [HBoarder(*map(int, input().split())) for _ in range(M)]
  
      y_axis = list(set([b.y for b in vborders]))
      y_axis.sort()
      y_axis = [y_axis[0] - 1] + y_axis + [y_axis[-1] + 1]
      x_axis = list(set([b.x for b in hborders]))
      x_axis.sort()
      x_axis = [x_axis[0] - 1] + x_axis + [x_axis[-1] + 1]
  
      cells = [
          [Cell(x1, y1, x2, y2) for x1, x2 in zip(x_axis[:-1], x_axis[1:])]
          for y1, y2 in zip(y_axis[:-1], y_axis[1:])
      ]
  
      for b in vborders:
          y_idx = bisect.bisect_left(y_axis, b.y)
          x_idx1 = bisect.bisect_left(x_axis, b.x1)
          x_idx2 = bisect.bisect_right(x_axis, b.x2) - 1
  
          for x_idx in range(x_idx1, x_idx2):
              cells[y_idx - 1][x_idx].down = False
              cells[y_idx][x_idx].up = False
  
      for b in hborders:
          x_idx = bisect.bisect_left(x_axis, b.x)
          y_idx1 = bisect.bisect_left(y_axis, b.y1)
          y_idx2 = bisect.bisect_right(y_axis, b.y2) - 1
  
          for y_idx in range(y_idx1, y_idx2):
              cells[y_idx][x_idx - 1].right = False
              cells[y_idx][x_idx].left = False
  
      queue = collections.deque()
      area = 0
  
      x = bisect.bisect_right(x_axis, 0.5) - 1
      y = bisect.bisect_right(y_axis, 0.2) - 1
      queue.append((x, y))
  
      while len(queue) != 0:
          x, y = queue.popleft()
  
          if x == 0 or x == len(x_axis) - 1 or y == 0 or y == len(y_axis) - 1:
              print("INF")
              return
  
          c = cells[y][x]
  
          if c.checked:
              continue
  
          area += c.area()
          c.checked = True
  
          if c.up:
              queue.append((x, y - 1))
  
          if c.down:
              queue.append((x, y + 1))
  
          if c.left:
              queue.append((x - 1, y))
  
          if c.right:
              queue.append((x + 1, y))
  
      print(area)
  
  
  if __name__ == "__main__":
      main()
  
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."}]