#include <bits/stdc++.h>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;


//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)


struct Edge {
    int to, from;
    ll cost;
    Edge(int from, int to, ll cost): from(from), to(to), cost(cost) {}
};

typedef vector<vector<Edge>> AdjList;
AdjList graph;

int main() {
    //cin.tie(0);
    //ios::sync_with_stdio(false);
    //cout << fixed << setprecision(10);

    
    ll H, W; cin >> H >> W;

    ll ans = INT_MAX;
    if(H%3==0 || W%3 == 0) cout << 0 << endl;
    else{

        for(int i=1; i<H; ++i){
            ll S1 = W*i;

            ll nokori = H-i;

            ll S2, S3;
            if(W%2 == 0){
                S2 = W/2 * nokori;
                S3 = S2;
            }else{
                S2 = W/2 * nokori;
                S3 = (W/2+1)*nokori;
            }

            ans = min(ans, max({S1, S2, S3}) - min({S1, S2, S3}));
            
        }

        for(int i=1; i<H-1; ++i){
            ll S1 = W*i;

            ll nokori = H-i;

            ll S2, S3;
            if(nokori%2 == 0){
                S2 = nokori/2 * W;
                S3 = S2;
            }else{
                S2 = nokori/2 * W;
                S3 = (nokori/2+1)*W;
            }

            ans = min(ans, max({S1, S2, S3}) - min({S1, S2, S3}));
            
        }
        for(int i=1; i<W; ++i){
            ll S1 = H*i;

            ll nokori = W-i;

            ll S2, S3;
            if(H%2 == 0){
                S2 = H/2 * nokori;
                S3 = S2;
            }else{
                S2 = H/2 * nokori;
                S3 = (H/2+1)*nokori;
            }

            ans = min(ans, max({S1, S2, S3}) - min({S1, S2, S3}));
        }

        for(int i=1; i<W-1; ++i){
            ll S1 = H*i;

            ll nokori = W-i;

            ll S2, S3;
            if(nokori%2 == 0){
                S2 = nokori/2 * H;
                S3 = S2;
            }else{
                S2 = nokori/2 * H;
                S3 = (nokori/2+1)*H;
            }

            ans = min(ans, max({S1, S2, S3}) - min({S1, S2, S3}));
        }
        cout << ans << endl;
    }
    
    return 0;

}

Measured memory_bytes: 256