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

typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<bool> > vvb;
typedef map<int, bool> mib;

typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vpll;

typedef vector<string> vs;

typedef long double ld;

#define _GLIBCXX_DEBUG

#define REP(i,n) for (int i = 0; i < (n); ++i)
#define REPD(i,n) for (int i = (n-1); i >= 0; --i)
#define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y) cerr << #x << ": " << x << ", " << #y << ": " << y << '\n'
#define debug3(x, y, z) cerr << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << '\n'
#define debugs(s) cerr << s << "\n"
#define hyphen() cerr << "--\n"

#define ALL(vec) (vec).begin(), (vec).end()
#define REVALL(vec) (vec).rbegin(), (vec).rend()

static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

#define fst first
#define snd second
#define pb push_back
#define mk(x,y) make_pair((x),(y))

// http://ehafib.hatenablog.com/entry/2015/12/23/164137
int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int qpm(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

#define sz(v) int(v.size())

// x1, x2ライブラリとの被りを避ける
#define x1 x192837465
#define x2 x123456789
#define y1 y192837465
#define y2 y123456789

// typo
#define itn int
#define reutrn return
#define reutnr return

#define make(type, x) type x; cin>>x;
#define make2(type, x, y) type x, y; cin>>x>>y;
#define make3(type, x, y, z) type x, y, z; cin>>x>>y>>z;
#define make4(type, x, y, z, t) type x, y, z, t; cin>>x>>y>>z>>t;

const int MOD = (int)1e9 + 7;
const int INF = numeric_limits<int>::max();

int yokoshima(int H, int W) {
    int ans = INF;
    FORE(a, -1, 1) {
        FORE(b, -1, 1) {
            int h1 = (H / 3 + a);
            int h2 = (H / 3 + b);
            int h3 = H - h1 - h2;

            if (h1 < 1 || h2 < 1 || h3 < 1) {
                continue;
            }

            int s1 = W * h1;
            int s2 = W * h2;
            int s3 = W * h3;

            int maxs = max(max(s1, s2), s3);
            int mins = min(min(s1, s2), s3);
            if (maxs - mins < ans) {
                ans = maxs - mins;
            }
        }
    }

    return ans;
}

int enn(int H, int W) {
    int ans = INF;
    FORE(c, -1, 1) {
        FORE(d, -1, 1) {
            int h1 = H / 3 + c;
            int h2 = (H - h1);
            int w1 = W / 2 + d;
            int s1 = W * h1;
            int s2 = w1 * h2;
            int s3 = H * W - s1 - s2;

            if (h1 < 1 || h2 < 1 || w1 < 1 || s3 < 1) {
                continue;
            }

            int maxs = max(max(s1, s2), s3);
            int mins = min(min(s1, s2), s3);
            if (maxs - mins < ans) {
                ans = maxs - mins;
            }
        }

    }

    return ans;
}

signed main() {
    make2(int, H, W);

    int ans = INF;
    // よこしま
    int yoko = yokoshima(H, W);
    debug(yoko);
    ans = min(ans, yoko);

    // たてしま
    int tate = yokoshima(W, H);
    debug(tate);
    ans = min(ans, tate);

    // ロ日
    int yokoen =enn(W, H);
    debug(yokoen);
    ans = min(ans, yokoen);

    // 円
    int tateen = enn(H, W);
    debug(tateen);
    ans = min(ans, tateen);

    cout << ans << endl;
}


Measured memory_bytes: 3624