#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <time.h>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <string.h>

#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
using namespace std;

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <time.h>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <string.h>

#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
using namespace std;
int main(){
    ll h,w;
    sld(h) sld(w)
    if(h % 3 == 0 || w % 3 == 0){
        p(0) pn
    }else{
        ll mini = min(h,w);
        ll s1,s2,s3;
        ll x = h/3;
        s1 = x*w;
        if(w % 2 == 0){
            s2 = (w/2)*(h-x);
            mini = min(abs(s1-s2),mini);
        }else{
            s2 = (w/2)*(h-x);
            s3 = (w/2+1)*(h-x);
            ll x = max(abs(s1-s2),abs(s1-s3));
            x = max(abs(s3-s2),x);
            mini = min(abs(x),mini);
        }
        x ++;
        s1 = x*w;
        if(w % 2 == 0){
            s2 = (w/2)*(h-x);
            mini = min(abs(s1-s2),mini);
        }else{
            s2 = (w/2)*(h-x);
            s3 = (w/2+1)*(h-x);
            ll x = max(abs(s1-s2),abs(s1-s3));
            x = max(abs(s3-s2),x);
            mini = min(abs(x),mini);
        }





        x = w/3;
        s1 = x*h;
        if(h % 2 == 0){
            s2 = (h/2)*(w-x);
            mini = min(abs(s1-s2),mini);
        }else{
            s2 = (h/2)*(w-x);
            s3 = (h/2+1)*(w-x);
            ll x = max(abs(s1-s2),abs(s1-s3));
            x = max(abs(s3-s2),x);
            mini = min(abs(x),mini);
        }
        x ++;
        s1 = x*h;
        if(h % 2 == 0){
            s2 = (h/2)*(w-x);
            mini = min(abs(s1-s2),mini);
        }else{
            s2 = (h/2)*(w-x);
            s3 = (h/2+1)*(w-x);
            ll x = max(abs(s1-s2),abs(s1-s3));
            x = max(abs(s3-s2),x);
            mini = min(abs(x),mini);
        }
        pld(mini) pn
    }
    return 0;
}


Measured memory_bytes: 256