def solve():

    H, W = list(map(int, input().split()))

    if H*W%3==0:

        return 0

    if H%2==0 and W%2==0:

        return min(H//2,W//2)

    if H%2==0:

        return min([H//2,H//3*2+W//2+1-min(H//3,W//2),W])

    if W%2==0:

        return min([W//2,W//3*2+H//2+1-min(W//3,H//2),H])

    return min([H//3*2+W//2+1-min(H//3,W//2),W//3*2+H//2+1-min(W//3,H//2),H,W])

print((solve()))
def solve():

  ans = float('inf')

  H, W = list(map(int, input().split()))

  for h in range(1,H):

    o1 = (H-h)//2*W

    o2 = (H-h)*W-o1

    a = [h*W,o1,o2]

    ans = min(ans,max(a)-min(a))

    o1 = W//2*(H-h)

    o2 = (H-h)*W-o1

    a = [h*W,o1,o2]

    ans = min(ans,max(a)-min(a))

  for w in range(1,W):

    o1 = (W-w)//2*H

    o2 = (W-w)*H-o1

    a = [w*H,o1,o2]

    ans = min(ans,max(a)-min(a))

    o1 = H//2*(W-w)

    o2 = (W-w)*H-o1

    a = [w*H,o1,o2]

    ans = min(ans,max(a)-min(a))

  return ans

print((solve()))
def solve():
    H, W = list(map(int, input().split()))
    if H * W % 3 == 0:
        return 0
    if H % 2 == 0 and W % 2 == 0:
        return min(H // 2, W // 2)
    if H % 2 == 0:
        return min([H // 2, H // 3 * 2 + W // 2 + 1 - min(H // 3, W // 2), W])
    if W % 2 == 0:
        return min([W // 2, W // 3 * 2 + H // 2 + 1 - min(W // 3, H // 2), H])
    return min(
        [
            H // 3 * 2 + W // 2 + 1 - min(H // 3, W // 2),
            W // 3 * 2 + H // 2 + 1 - min(W // 3, H // 2),
            H,
            W,
        ]
    )


print((solve()))

def solve():
    ans = float("inf")
    H, W = list(map(int, input().split()))
    for h in range(1, H):
        o1 = (H - h) // 2 * W
        o2 = (H - h) * W - o1
        a = [h * W, o1, o2]
        ans = min(ans, max(a) - min(a))
        o1 = W // 2 * (H - h)
        o2 = (H - h) * W - o1
        a = [h * W, o1, o2]
        ans = min(ans, max(a) - min(a))
    for w in range(1, W):
        o1 = (W - w) // 2 * H
        o2 = (W - w) * H - o1
        a = [w * H, o1, o2]
        ans = min(ans, max(a) - min(a))
        o1 = H // 2 * (W - w)
        o2 = (W - w) * H - o1
        a = [w * H, o1, o2]
        ans = min(ans, max(a) - min(a))
    return ans


print((solve()))

+    ans = float("inf") -    if H * W % 3 == 0: -        return 0 -    if H % 2 == 0 and W % 2 == 0: -        return min(H // 2, W // 2) -    if H % 2 == 0: -        return min([H // 2, H // 3 * 2 + W // 2 + 1 - min(H // 3, W // 2), W]) -    if W % 2 == 0: -        return min([W // 2, W // 3 * 2 + H // 2 + 1 - min(W // 3, H // 2), H]) -    return min( -        [ -            H // 3 * 2 + W // 2 + 1 - min(H // 3, W // 2), -            W // 3 * 2 + H // 2 + 1 - min(W // 3, H // 2), -            H, -            W, -        ] -    ) +    for h in range(1, H): +        o1 = (H - h) // 2 * W +        o2 = (H - h) * W - o1 +        a = [h * W, o1, o2] +        ans = min(ans, max(a) - min(a)) +        o1 = W // 2 * (H - h) +        o2 = (H - h) * W - o1 +        a = [h * W, o1, o2] +        ans = min(ans, max(a) - min(a)) +    for w in range(1, W): +        o1 = (W - w) // 2 * H +        o2 = (W - w) * H - o1 +        a = [w * H, o1, o2] +        ans = min(ans, max(a) - min(a)) +        o1 = H // 2 * (W - w) +        o2 = (W - w) * H - o1 +        a = [w * H, o1, o2] +        ans = min(ans, max(a) - min(a)) +    return ans