fun main(args: Array<String>) {
    val (h,w)= readLine()!!.split(" ").map{it.toLong()}
    if(h%3==0L || w%3==0L){
        println(0)
        return
    }
    var diff=Math.min(h,w)

    diff = Math.min(diff, divideT(h,w))
    diff = Math.min(diff, divideT(w,h))

    println(diff)
}

fun divideT(h:Long, w:Long):Long{
    val l=w/2
    val r=(w+1)/2
    var d=Long.MAX_VALUE
    for(i in 1..h-1){
        d = Math.min( d,
                Math.max( i*w, Math.max((h-i)*l,(h-i)*r) )
                -Math.min( i*w, Math.min((h-i)*l,(h-i)*r) )
        )
    }
    return d
}