object Main extends App {
  val sc = new FastScanner(System.in)
  val n, m = sc.nextInt()
  var xs, ys = List[Int](0)
  var lx, ly = List[(Int, Int, Int)]()
  for (i <- 1 to n) {
    val a, b, c = sc.nextInt()
    lx ::= (a,b,c)
    xs ::= a
    xs ::= b
    ys ::= c
  }
  for (i <- 1 to m) {
    val d, e, f = sc.nextInt()
    ly ::= (d,e,f)
    xs ::= d
    ys ::= e
    ys ::= f
  }

  val xsSorted = xs.distinct.sorted.toVector
  val ysSorted = ys.distinct.sorted.toVector

  val h = xsSorted.length
  val w = ysSorted.length
  val xCmp = xsSorted.zipWithIndex.toMap
  val yCmp = ysSorted.zipWithIndex.toMap
  val lxCmp = lx.map{case (x1,x2,y) => (xCmp(x1),xCmp(x2),yCmp(y))}
  val lyCmp = ly.map{case (x,y1,y2) => (xCmp(x),yCmp(y1),yCmp(y2))}
  val xWidth = Vector.tabulate(h-1)(x => (xsSorted(x+1) - xsSorted(x)).toLong)
  val yWidth = Vector.tabulate(w-1)(y => (ysSorted(y+1) - ysSorted(y)).toLong)

  val visited = Array.fill((2*h + 1) * 6010 + 2*w + 1)(false)
  for {
    (x1,x2,y) <- lxCmp
    x <- 2*x1 + 1 to 2*x2 + 1
  } {
    visited(x * 6010 + y*2 + 1) = true
  }
  for {
    (x,y1,y2) <- lyCmp
    y <- 2*y1 + 1 to 2*y2 + 1
  } {
    visited((x*2 + 1) * 6010 + y) = true
  }

  val xInit = xCmp(0) * 2
  val yInit = yCmp(0) * 2

  var ans = 0L
  var queue = List(xInit * 6010 + yInit)
  val d = List((1,0),(-1,0),(0,1),(0,-1))

  if (xCmp(0) == 0 || xCmp(0) == h - 1 || yCmp(0) == 0 || yCmp(0) == w - 1) {
    ans = -1
    queue = Nil
  } else {
    visited(xInit * 6010 + yInit) = true
    ans += xWidth(xInit/2 - 1) * yWidth(yInit/2 - 1)
  }

  while (queue.nonEmpty) {
    val z = queue.head
    val x = z / 6010
    val y = z % 6010
    queue = queue.tail
    for ((dx, dy) <- d) {
      val x1 = x + dx
      val x2 = x + 2 * dx
      val y1 = y + dy
      val y2 = y + 2 * dy
      if (!visited(x1 * 6010 + y1) && !visited(x2 * 6010 + y2)) {
        if (x2 == 0 || x2 == 2*h || y2 == 0 || y2 == 2*w) {
          ans = -1
          queue = Nil
        } else {
          queue ::= x2 * 6010 + y2
          visited(x2 * 6010 + y2) = true
          if (x2 % 2 == 0 && y2 % 2 == 0) {
            ans += xWidth(x2/2 - 1) * yWidth(y2/2 - 1)
          }
        }
      }
    }
  }

  println(if (ans == -1) "INF" else ans)
}

class FastScanner(source: java.io.InputStream) {
  val buf = new Array[Byte](1024)
  var now, end = 0

  def isPrintable(b: Byte): Boolean = 33 <= b && b <= 126
  def isNum(b: Byte): Boolean = 48 <= b && b <= 57

  def hasNextByte(): Boolean = {
    if (now < end) {
      true
    } else {
      now = 0
      end = source.read(buf)
      end > 0
    }
  }

  def nextByte(): Byte = {
    if (hasNextByte()) {
      val b = buf(now)
      now += 1
      b
    } else {
      -1
    }
  }

  def hasNext(): Boolean = {
    while (hasNextByte() && !isPrintable(buf(now))) {
      now += 1
    }
    hasNextByte()
  }

  def next(): String = {
    if (hasNext()) {
      val sb = new StringBuilder()
      var b = nextByte()
      while (isPrintable(b)) {
        sb += b.toChar
        b = nextByte()
      }
      sb.toString
    } else {
      throw new NoSuchElementException()
    }
  }

  def nextInt(): Int = {
    nextLong().toInt
  }

  def nextLong(): Long = {
    if (hasNext()) {
      var b = nextByte()
      var sign = 1
      var n = 0L
      if (b == '-') {
        sign = -1
        b = nextByte()
      }
      while (isNum(b)) {
        n = n * 10 + (b - 48)
        b = nextByte()
      }
      sign * n
    } else {
      throw new NoSuchElementException()
    }
  }

  def nextDouble(): Double = next().toDouble
}


Measured memory_bytes: 333968