import std.algorithm,
       std.string,
       std.range,
       std.stdio,
       std.conv;

bool chmin(ref long a, long b) {
  if (b < a) {
    a = b;
    return true;
  } else {
    return false;
  }
}

long ans = long.max;

void solve(long i, long H, long W) {
  {
    long j = (H - i) / 2;
    long[] Ss;
    Ss = [i * W, j*W, (H-j-i)*W];
    sort!"a<b"(Ss);
    chmin(ans, Ss[2] - Ss[0]);
  }
  {
    long h = H - i;
    long j = W / 2;
    long[] Ss;
    Ss = [i * W, j*h, (W-j)*h];
    sort!"a<b"(Ss);
    chmin(ans, Ss[2] - Ss[0]);
  }
}

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

  foreach (_i; 0..H) {
    long i = _i + 1;
    solve(i, H, W);
  }

  foreach (_i; 0..W) {
    long i = _i + 1;
    solve(i, W, H);    
  }
  writeln(ans);
}
