#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll H,W;
    cin>>H>>W;
    
    ll ans=1e12;
    
    for(int k=0;k<2;k++){
        if(k)swap(H,W);
        for(int i=1;i<H;i++){
            ll h=H-i;
            ll Sa=i*W,Sb,Sc;
            
            ll case1;
            Sb=(h/2)*W;
            Sc=(h-h/2)*W;
            case1=max({abs(Sa-Sb),abs(Sc-Sb),abs(Sc-Sa)});
            ans=min(ans,case1);
            
            ll case2;
            Sb=h*(W/2);
            Sc=h*(W-W/2);
            case2=max({abs(Sa-Sb),abs(Sc-Sb),abs(Sc-Sa)});
            ans=min(ans,case2);
        }
    }
    
    cout<<ans<<endl;
}
