#include <algorithm>
#include <iostream>

using namespace std;
using ll = long long;

ll s(ll H, ll W) {
  ll ret = H + W, d;
  for (ll i : {0, 1}) {
    ll h1 = H / 3 + i, a1 = h1 * W, hr = H - h1;
    if (hr * W % 2) {
      ll x = min(hr, W), a2 = (hr * W + x) / 2, a3 = a2 - x;
      auto [m, M] = minmax({a1, a2, a3});
      d = M - m;
    } else {
      d = abs(a1 - hr * W / 2);
    }
    ret = min(ret, d);
  }
  return ret;
}

int main() {
  ll H, W, ans{};
  cin >> H >> W;
  if (H * W % 3) ans = min(s(H, W), s(W, H));
  cout << ans << endl;
}
