#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    ll H, W; cin >> H >> W;
    if(H % 3 == 0 || W % 3 == 0) cout << 0 << endl;
    else{/*
        if(H % 2 == 0){
            if(W % 3 == 1){
                ll Smax = H / 2 * (W - (W-1)/3);
                ll Smin = (W-1)/3 * H;
                cout << Smax - Smin << endl;
            }else{
                ll Smax = (W+1)/3 * H;
                ll Smin = H / 2 * (W - (W+1)/3);
                cout << Smax - Smin << endl;
            }
        }else if(W % 2 == 0){
            if(H % 3 == 1){
                ll Smax = W / 2 * (H - (H-1)/3);
                ll Smin = (H-1)/3 * W;
                cout << Smax - Smin << endl;
            }else{
                ll Smax = (H+1)/3 * W;
                ll Smin = W / 2 * (H - (H+1)/3);
                cout << Smax - Smin << endl;
            }
        }else{*/
            ll Smax1, Smax2, Smin1, Smin2, Smax3, Smin3, Smax4, Smin4;
            if(W % 3 == 1){
                ll Sa = H * (W - 1) /3;
                ll Sb = (H / 2) * (W - W/3);
                ll Sc = (H - H/2) *  (W - W/3);
                Smax1 = max(Sa, max(Sb, Sc));
                Smin1 = min(Sa, min(Sb, Sc));
            }else{
                ll Sa = H * (W + 1) /3;
                ll Sb = (H / 2) * (W - (W + 1)/3);
                ll Sc = (H - H/2) *  (W - (W + 1)/3);
                Smax1 = max(Sa, max(Sb, Sc));
                Smin1 = min(Sa, min(Sb, Sc));
            }
            
            if(H % 3 == 1){
                ll Sa = W * (H - 1) /3;
                ll Sb = (W / 2) * (H - H/3);
                ll Sc = (W - W/2) *  (H - H/3);
                Smax2 = max(Sa, max(Sb, Sc));
                Smin2 = min(Sa, min(Sb, Sc));
            }else{
                ll Sa = W * (H + 1) /3;
                ll Sb = (W / 2) * (H - (H + 1)/3);
                ll Sc = (W - W/2) * (H - (H + 1)/3);
                Smax2 = max(Sa, max(Sb, Sc));
                Smin2 = min(Sa, min(Sb, Sc));
            }


            /*
            if(W % 3 == 1){
                ll Sa = H * (W + 2) /3;
                ll Sb = (H / 2) * (W - (W+2)/3);
                ll Sc = (H - H/2) *  (W - (W+2)/3);
                Smax3 = max(Sa, max(Sb, Sc));
                Smin3 = min(Sa, min(Sb, Sc));
            }else{
                ll Sa = H * (W - 2) /3;
                ll Sb = (H / 2) * (W - (W - 2)/3);
                ll Sc = (H - H/2) *  (W - (W - 2)/3);
                Smax3 = max(Sa, max(Sb, Sc));
                Smin3 = min(Sa, min(Sb, Sc));
            }

            if(H % 3 == 1){
                ll Sa = W * (H + 2) /3;
                ll Sb = (W / 2) * (H - H/3 - 1);
                ll Sc = (W - W/2) *  (H - H/3 - 1);
                Smax4 = max(Sa, max(Sb, Sc));
                Smin4 = min(Sa, min(Sb, Sc));
            }else{
                ll Sa = W * (H - 2) /3;
                ll Sb = (W / 2) * (H - (H - 2)/3);
                ll Sc = (W - W/2) * (H - (H - 2)/3);
                Smax4 = max(Sa, max(Sb, Sc));
                Smin4 = min(Sa, min(Sb, Sc));
            }
            */

            cout << min(min(Smax1 - Smin1, Smax2 - Smin2), min(H, W)) << endl;
        
    }
}

Measured memory_bytes: 256