fun main(args: Array<String>) {
    val (H, W) = listOfLong()
    var ans = Long.MAX_VALUE
    if (H * W % 3 == 0L) return println(0)
    fun solv(H: Long, W: Long) {
        for (h in 1 until H) {
            val d1 = h * W
            for (n in 0 .. 1) {
                val d2 =
                    if (n == 0) (H - h) / 2 * W // 三型
                    else (H - h) * (W / 2)      // Ｔ型
                val d3 = (H * W) - d1 - d2
                val d = listOf(d1, d2, d3).sorted()
                ans = Math.min(ans, d.last() - d.first())
            }
        }
    }
    solv(H, W)
    if (W != H) solv(W, H)
    println(ans)
}
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfInt(vararg deltas: Int) = listOfString().map { Integer.parseInt(it) }.mapIndexed { index, int -> int + deltas[index % deltas.size] }
fun listOfLong(offset: Long = 0L) = listOfString().map { it.toLong() + offset}
