
object MainKt {
  @JvmStatic fun main(args:Array<String>) {
    val (H,W)=readLine()!!.split(" ").map(String::toLong)

    val ans =   if(H%3 ==0L || W %3 == 0L){0L} else {
      val side_h = (1.until(W)).fold(H*W) { res,col ->
        val adjustor=if(H%2==0L) {0L} else {1L}
        val piece=arrayOf(H*col,(H-adjustor)*(W-col)/2,(H+adjustor)*(W-col)/2)
        
        arrayOf(piece.max()!!-piece.min()!!,res).min()!!
      } 
      val side_w = (1.until(H)).fold(H*W) { res,row ->
        val adjustor=if(W%2==0L) {0L} else {1L}
        val piece=arrayOf(W*row,(W-adjustor)*(H-row)/2,(W+adjustor)*(H-row)/2)
      arrayOf(piece.max()!!-piece.min()!!,res).min()!!
      }
      arrayOf(arrayOf(side_h,H).min()!!,arrayOf(side_w,W).min()!!).min()!!
    }      
    println(ans)
  }
}
