main=do
 [h,w]<-map read.words<$>getLine
 print$min(solve h w)(solve w h)
solve h w=min(a h w)(b h w)
a h w=minimum[(maximum x)-(minimum x)|i<-[1..w-1],let x=[h`div`2*i,(h-h`div`2)*i,h*(w-i)]]
b h w=minimum[(maximum x)-(minimum x)|i<-[2..w-1],let x=[i`div`2*h,(i-i`div`2)*h,(w-i)*h]]