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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 45;
const int mod = 1000000007;

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

// h(n, r) = c(n+r-1, r)
struct combination
{
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1)
  {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i)
    fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i)
    ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k)
  {
    if (k < 0 || k > n)
    return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int main()
{
  ll h, w;
  cin >> h >> w;
  ll ans = INF64;
  for(ll i = 1; i <= h-2; ++i) {
    vector<ll> choco;
    choco.push_back(i*w);
    ll h1 = (h-i)/2, h2 = h-i-h1;
    choco.push_back(h1*w);
    choco.push_back(h2*w);
    chmin(ans, *max_element(ALL(choco))-*min_element(ALL(choco)));
  }
  for(ll i = 1; i <= h-1; ++i) {
    vector<ll> choco;
    choco.push_back(i*w);
    ll w1 = w/2, w2 = w-w1;
    choco.push_back((h-i)*w1);
    choco.push_back((h-i)*w2);
    chmin(ans, *max_element(ALL(choco))-*min_element(ALL(choco)));
  }
  for(ll j = 1; j <= w-2; ++j) {
    vector<ll> choco;
    choco.push_back(h*j);
    ll w1 = (w-j)/2, w2 = w-j-w1;
    choco.push_back(h*w1);
    choco.push_back(h*w2);
    chmin(ans, *max_element(ALL(choco))-*min_element(ALL(choco)));
  }
  for(ll j = 1; j <= w-1; ++j) {
    vector<ll> choco;
    choco.push_back(h*j);
    ll h1 = h/2, h2 = h-h1;
    choco.push_back((w-j)*h1);
    choco.push_back((w-j)*h2);
    chmin(ans, *max_element(ALL(choco))-*min_element(ALL(choco)));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256