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: N, M = map(int, input().split())
  
  ts = {}
  tlis = []
  
  for i in range(N):
      B, C, A = map(int, input().split())
  
      if A not in ts:
          tlis.append(A)
          ts[A] = []
      ts[A].append([B, C])
  
  ys = {}
  ylis = []
  
  for i in range(M):
      A, B, C = map(int, input().split())
  
      if A not in ys:
          ylis.append(A)
          ys[A] = []
      ys[A].append([B, C])
  
  tlis.sort()
  ylis.sort()
  
  import bisect
  
  nowi = bisect.bisect_right(tlis, 0) - 1
  nowj = bisect.bisect_right(ylis, 0) - 1
  
  # print (tlis,ylis,nowi,nowj)
  
  for i in ts:
  
      ts[i].sort()
  
      new = []
      lastl = None
      lastr = None
  
      for tmp in ts[i]:
          nl, nr = tmp
  
          if lastl == None:
              lastl = nl
              lastr = nr
  
          elif lastr < nl:
              new.append([lastl, lastr])
              lastl = nl
              lastr = nr
  
          else:
              lastr = nr
  
      new.append([lastl, lastr])
      ts[i] = new
  
  for i in ys:
  
      ys[i].sort()
  
      new = []
      lastl = None
      lastr = None
  
      for tmp in ys[i]:
          nl, nr = tmp
  
          if lastl == None:
              lastl = nl
              lastr = nr
  
          elif lastr < nl:
              new.append([lastl, lastr])
              lastl = nl
              lastr = nr
  
          else:
              lastr = nr
  
      new.append([lastl, lastr])
      ys[i] = new
  
  
  from collections import deque
  
  q = deque([[nowi, nowj]])
  import sys
  
  ans = 0
  
  end = {}
  end[(nowi, nowj)] = 1
  
  if len(tlis) < 2 or len(ylis) < 2:
      print("INF")
      sys.exit()
  
  while len(q) > 0:
  
      ni, nj = q.popleft()
  
      if ni == -1 or nj == -1 or ni == len(tlis) - 1 or nj == len(ylis) - 1:
          print("INF")
          sys.exit()
  
      up = ylis[nj]
      do = ylis[nj + 1]
      le = tlis[ni]
      ri = tlis[ni + 1]
  
      # print (ni,nj,up,do,le,ri)
  
      ans += (do - up) * (ri - le)
  
      # up
      flag = True
  
      nex = (ni, nj - 1)
  
      if nex not in end:
          for tmp in ys[up]:
              L, R = tmp
  
              if L <= le and ri <= R:
                  flag = False
                  break
  
          if flag:
              end[nex] = 1
              q.append([nex[0], nex[1]])
  
      nex = (ni, nj + 1)
      flag = True
  
      if nex not in end:
          for tmp in ys[do]:
              L, R = tmp
  
              if L <= le and ri <= R:
                  flag = False
                  break
  
          if flag:
              end[nex] = 1
              q.append([nex[0], nex[1]])
  
      nex = (ni - 1, nj)
      flag = True
      if nex not in end:
          for tmp in ts[le]:
              L, R = tmp
  
              if L <= up and do <= R:
                  flag = False
                  break
  
          if flag:
              end[nex] = 1
              q.append([nex[0], nex[1]])
  
      nex = (ni + 1, nj)
      flag = True
      if nex not in end:
          for tmp in ts[ri]:
              L, R = tmp
  
              if L <= up and do <= R:
                  flag = False
                  break
  
          if flag:
              end[nex] = 1
              q.append([nex[0], nex[1]])
  
  print(ans)
  
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."}]