#include <cstdio>
#include <cstdlib>
#include <cstddef>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <cstdint>

// C++11-compatible FastIO
namespace FastIO{static constexpr size_t E=(1<<17);static constexpr size_t T=23
,A=334;static constexpr char O[]="%.16f";FILE*e=stdin,*t=stdout;char a[E|1],*o,
*i;char n[E|1],*s,*h;inline size_t r(){size_t g=fread(a,1,E,e);*(i=a+g)=0;o=a;
return g;}inline size_t d(){std::ptrdiff_t g=i-o;if(a+g>=o){return 0;}memcpy(a,
o,g);size_t v=fread(a+g,1,E-g,e);*(i=a+(g+=v))=0;o=a;return v;}inline void l(d\
ouble&g){if(*o==0&&r()){g=0;return;}char*b;g=strtod(o,&b);while(b==o){if(!r()){
g=0;return;}g=strtod(o,&b);}if(b==i&&d()){g=strtod(a,&b);}o=b;}inline void l(c\
har&g){if(*o==0){r();}if((g=*o)!=0){++o;}}inline void l(char*g){while(1){if(*o
==0&&!r()){*g=0;return;}if(*o<=' '){++o;}else{break;}}for(char*b=o;;++o){if(*o
==0){memcpy(g,b,o-b);g+=o-b;if(!r()){*g=0;return;}b=o;}else if(*o<=' '){memcpy(
g,b,o-b);g+=o-b;*g=0;return;}}}template<class N>inline void l(N&g,typename std
::enable_if<std::is_signed<N>::value>::type*y=0){g=0;int p=0;if(o+T>=i){d();}w\
hile(*o<'-'){++o;}if(*o=='-'){p=1;++o;}do{g=g*10+*o-'0';}while(*++o>='0');++o;
if(p){g=-g;}}template<class N>inline void l(N&g,typename std::enable_if<!std::
is_signed<N>::value>::type*y=0){g=0;if(o+T>=i){d();}while(*o<'0'){++o;}do{g=g*
10+*o-'0';}while(*++o>='0');++o;}inline void c(){while((*o!=0||r())&&*o++<=' ')
{}}inline void c(char g){while((*o!=0||r())&&*o++<=' '){}}inline void u(){fwri\
te(n,1,s-n,t);s=n;}inline void m(char g){if(s+1>=h)u();*s++=g;}inline void m(c\
onst char*g){size_t y=strlen(g);if(s+y>=h){u();}if(s+y>=h){fwrite(g,1,y,t);}el\
se{memcpy(s,g,y);s+=y;}}template<size_t N>inline void m(const char(&g)[N]){m(&g
[0]);}inline void m(double g){char y[A];size_t p=snprintf(y,A,O,g);char*b=s+p;
if(b>=h){u();b=n+p;}memcpy(s,y,p);s=b;}template<class N>inline void m(N g,type\
name std::enable_if<std::is_signed<N>::value>::type*y=0){if(s+T>=h){u();}if(g==
0){*s++='0';return;}char k[T],*j=k+T,*x=j;if(g<0){*s++='-';g=-g;}do{*--j=g%10+
'0';g/=10;}while(g);memcpy(s,j,x-j);s+=x-j;}template<class N>inline void m(N g,
typename std::enable_if<!std::is_signed<N>::value>::type*y=0){if(s+T>=h){u();}
if(g==0){*s++='0';return;}char v[T],*k=v+T,*j=k;do{*--k=g%10+'0';g/=10;}while(g
);memcpy(s,k,j-k);s+=j-k;}struct Scanner{Scanner(){o=a;i=a+E;r();}template<cla\
ss Z>inline void scan(Z&&z){l(z);}template<class Z,class...Q>inline void scan(Z
&&z,Q&&...q){l(z);scan(q...);}};struct Printer{Printer(){s=n;h=n+E;}~Printer(){
u();}template<class Z>inline void print(Z z){m(z);}template<class Z,class...Q>
inline void print(Z z,Q...q){m(z);print(q...);}template<class Z>inline void pr\
intln(Z z){m(z);m('\n');}};}

FastIO::Scanner cin;
FastIO::Printer cout;

int main() {
    int64_t H, W;
    cin.scan(H, W);

    if (H % 3 == 0 || W % 3 == 0) {
        cout.println("0");
        return 0;
    }

    int64_t res=std::min(H, W);
    for (int64_t i=1; i<H; ++i) {
        int64_t a=i*W;
        int64_t b=(H-i)*(W/2);
        int64_t c=H*W-a-b;

        int64_t max=std::max(a, std::max(b, c));
        int64_t min=std::min(a, std::min(b, c));

        res = std::min(res, max-min);
    }

    std::swap(H, W);

    for (int64_t i=1; i<H; ++i) {
        int64_t a=i*W;
        int64_t b=(H-i)*(W/2);
        int64_t c=H*W-a-b;

        int64_t max=std::max(a, std::max(b, c));
        int64_t min=std::min(a, std::min(b, c));

        res = std::min(res, max-min);
    }

    cout.println(res);
    return 0;
}


Measured memory_bytes: 256