fun main(args: Array<String>) {
    val (H, W) = readLine()!!.split(" ").map(String::toInt)
    if (H % 3 == 0 || W % 3 == 0) {
        println(0)
    } else {
        val result = split(H, W, 3)
        println(result.max()!! - result.min()!!)
    }
}

private fun split(h: Int, w: Int, n: Int): MutableList<Long> {
    if (n == 1) {
        return mutableListOf(h * w.toLong())
    }
    val a = calc(h, w, n)
    val b = calc(w, h, n)
    return if (a.max()!! - a.min()!! < b.max()!! - b.min()!!) a else b
}

private fun calc(h: Int, w: Int, n: Int): MutableList<Long> {
    val length = Math.round(h / n.toDouble()).toInt()
    val result = split(h - length, w, n - 1)
    result.add(length.toLong() * w)
    return result
}
