/*I MAY NOT GET THE SUCCESS IMMEDIATELY BUT I WILL GET IT FOR SURE*/
#include<bits/stdc++.h>
#define opt std::ios_base::sync_with_stdio(false)
#define I int
#define li      int32_t
#define lli     long long
#define ulli unsigned long long
 
#define pn          printf("\n")
#define nl          cout<<'\n'
#define sf(N)       scanf("%lld",&N)
#define pf(N)       printf("%lld",N)
#define sl          cout<<' '
#define ps          printf(" ")
 
#define rep(i,a,b)  for(i=a;i<b;i++)
#define repr(i,a,b) for(i=a;i>b;i--)
#define elif        else if
#define mset(a,b)   memset(a,b,sizeof(a))
 
#define pb      push_back
#define pob     pop_back
#define itr     iterator
#define sz()    size()
#define szof    sizeof
#define lb      lower_bound
#define ub      upper_bound
#define mp      make_pair
#define vlli    vector<lli>
#define plli    pair<lli,lli>
#define vplli   vector<plli >
#define F       first
#define S       second
#define Dup erase(unique(V.begin(),V.end()),V.end())
 
#define TC int test; cin>>test; test++; while(--test)
 
#define Inf     1000000000000000
#define mod     1000000007
#define M1      1000000007
#define M2      1000000009
using namespace std;

char ch[105][105];

lli Power(lli a,lli b)
{
    lli result=1;
 
    while(b)
    {
        if(b%2)
        {
            result=(result*a)%mod;
        }
 
        b=b>>1;
        a=(a*a)%mod;
    }
 
 return result;
}
 
int main()
{
    opt;
 
    /*#ifndef ONLINE_JUDGE
    freopen("double_squares.txt","r",stdin);
    freopen("double_squares_out.txt","w",stdout);
    #endif // ONLINE_JUDGE*/
    
    lli l,b;
    cin>>l>>b;
    
    if(l%3==0 or b%3==0)
    {
        cout<<0;
        exit(0);
    }
    
    lli l1,l2;
    l1=ceil((l*b*1.0)/(b+floor(b/2.0)));
    l2=floor((l*b*1.0)/(b+floor(b/2.0)));
    
    lli b1,b2;
    b1=ceil((l*b*1.0)/(l+floor(l/2.0)));
    b2=floor((l*b*1.0)/(l+floor(l/2.0)));
    
    lli a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12;
    
    a1=b*(l-l1);
    a2=l1*ceil(b/2.0);
    a3=l1*floor(b/2.0);
    
    a4=ceil(b/2.0)*(l2);
    a5=floor(b/2.0)*(l2);
    a6=b*(l-l2);
    
    a7=l*(b-b1);
    a8=b1*ceil(l/2.0);
    a9=b1*floor(l/2.0);
    
    a10=ceil(l/2.0)*(b2);
    a11=floor(l/2.0)*(b2);
    a12=l*(b-b2);
    
    lli Amax1,Amin1,Amax2,Amin2,Amax3,Amin3,Amax4,Amin4;
    Amax1=max(a1,max(a2,a3));
    Amin1=min(a1,min(a2,a3));
    
    Amax2=max(a4,max(a5,a6));
    Amin2=min(a4,min(a5,a6));
    
    Amax3=max(a7,max(a8,a9));
    Amin3=min(a7,min(a8,a9));
    
    Amax4=max(a10,max(a12,a11));
    Amin4=min(a10,min(a12,a11));
    
    Amax1-=Amin1;
    Amax2-=Amin2;
    Amax3-=Amin3;
    Amax4-=Amin4;
    
    lli x=min(Amax1,min(Amax2,min(Amax3,Amax4)));
    
    l1=ceil((l*b*1.0)/(b+ceil(b/2.0)));
    l2=floor((l*b*1.0)/(b+ceil(b/2.0)));
    
    b1=ceil((l*b*1.0)/(l+ceil(l/2.0)));
    b2=floor((l*b*1.0)/(l+ceil(l/2.0)));
    
    a1=b*(l-l1);
    a2=l1*ceil(b/2.0);
    a3=l1*floor(b/2.0);
    
    a4=ceil(b/2.0)*(l2);
    a5=floor(b/2.0)*(l2);
    a6=b*(l-l2);
    
    a7=l*(b-b1);
    a8=b1*ceil(l/2.0);
    a9=b1*floor(l/2.0);
    
    a10=ceil(l/2.0)*(b2);
    a11=floor(l/2.0)*(b2);
    a12=l*(b-b2);
    
    Amax1=max(a1,max(a2,a3));
    Amin1=min(a1,min(a2,a3));
    
    Amax2=max(a4,max(a5,a6));
    Amin2=min(a4,min(a5,a6));
    
    Amax3=max(a7,max(a8,a9));
    Amin3=min(a7,min(a8,a9));
    
    Amax4=max(a10,max(a12,a11));
    Amin4=min(a10,min(a12,a11));
    
    Amax1-=Amin1;
    Amax2-=Amin2;
    Amax3-=Amin3;
    Amax4-=Amin4;
    
    lli y=min(Amax1,min(Amax2,min(Amax3,Amax4)));
    
    cout<<min(min(l,min(x,y)),b);
    
    
    
 
 return 0;
}

Measured memory_bytes: 256