main=getLine>>=print.solve.map read.words
solve[h,w]
 |h*w%3==0 = 0
 |otherwise=minimum$concatMap f [[h,w],[w,h]] where
  f[h,w]=[h,cx*h-(w-cx)*fy,(w-fx)*cy-fx*h] where
   (cx,fx,cy,fy)=((w+2)`div`3, w`div`3, (h+1)`div`2, h`div`2)