main=map read.words<$>getLine>>=print.minimum.f
 where f [h,w] =map(\l->(maximum l)-(minimum l))[((quot h 3)*w):(g (h-(quot h 3)) w),((quot h 3)*w+w):(g (h-(quot h 3)-1) w),((quot w 3)*h):(g h (w-(quot w 3))),((quot w 3)*h+h):(g h (w-(quot w 3)-1))]
       g h w =if(even(h*w))then[quot(h*w)2,quot(h*w)2]else[(quot(max h w)2)*(min h w),h*w-(quot(max h w)2)*(min h w)]