import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)

  val h = sc.nextLong
  val w = sc.nextLong

  val res =
    if (h % 3 == 0 || w % 3 == 0) 0
    else {
      val l = math.max(h, w)
      val s = math.min(h, w)

      val formT = {
        (1 to (s / 2).toInt).toVector.map { i =>
          val list = List(i * l, (s - i) * (l / 2), (s - i) * (l - l / 2)).sorted
          list.last - list.head
        }
      }.min

      val formTT = {
        (1 to (l / 2).toInt).toVector.map { j =>
          val list = List(j * s, (l - j) * (s / 2), (l - j) * (s - s / 2)).sorted
          list.last - list.head
        }
      }.min

      List(s,formT,formTT).min
    }

  println(res)
}