import std.functional,
       std.algorithm,
       std.string,
       std.traits,
       std.array,
       std.range,
       std.stdio,
       std.conv;

alias MIN = binaryFun!"a < b ? a : b";
alias MAX = binaryFun!"a > b ? a : b";
N abs(N)(N n) if (isNumeric!N) {
  return n * (n < 0 ? -1 : 1);
}

enum INF = 1001001001001001001UL;

struct Pair(A, B) {
  A first;
  B second;
}

Pair!(ulong, ulong) calc(ulong H, ulong W) {
  if (H % 2 == 0 || W % 2 == 0) {
    return typeof(return)(H * W / 2, H * W / 2);
  } else {
    return typeof(return)(H / 2 * W, H * W / 2);
  }
}

void main() {
  ulong[] HW = readln.chomp.split.to!(ulong[]);
  ulong H = HW[0],
        W = HW[1];
  ulong ans = INF;

  for (ulong i = 1; i < H - 1; i++) {
    ulong a = i * H;
    ulong b = (H - i) * W;
    ulong [] t;

    if (a < b) {
      auto p = calc(H - i, W);
      t ~= a;
      t ~= p.first;
      t ~= p.second;
    } else {
      auto p = calc(i, W);
      t ~= b;
      t ~= p.first;
      t ~= p.second;
    }
    t.sort!"a < b";
    if (ans > (t[2] - t[0])) {
      ans = t[2] - t[0];
    }
  }

  for (ulong i = 1; i < W - 1; i++) {
    ulong a = i * H;
    ulong b = (W - i) * H;
    ulong [] t;

    if (a < b) {
      auto p = calc(H, W - i);
      t ~= a;
      t ~= p.first;
      t ~= p.second;
    } else {
      auto p = calc(H, i);
      t ~= b;
      t ~= p.first;
      t ~= p.second;
    }
    t.sort!"a < b";
    if (ans > (t[2] - t[0])) {
      ans = t[2] - t[0];
    }
  }

  writeln(ans);
}
