def main():

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

    S = H * W

    ans = float('inf')

    for h1 in range(1,H):

        S1 = h1 * W

        # 縦に分割する場合

        h2 = (H - h1) // 2

        S2 = h2 * W

        S3 = (H - h1 - h2) * W

        ans = min(ans, max(S1,S2,S3) - min(S1,S2,S3))

        # 横に分割する場合

        w2 = W // 2

        w3 = W - w2

        S2 = (H - h1) * w2

        S3 = (H - h1) * w3

        ans = min(ans, max(S1,S2,S3) - min(S1,S2,S3))



    for w1 in range(1,W):

        S1 = w1 * H

        # 横に分割する場合

        w2 = (W - w1) // 2

        S2 = w2 * H

        S3 = (W - w1 - w2) * H

        ans = min(ans, max(S1,S2,S3) - min(S1,S2,S3))

        # 縦に分割する場合

        h2 = H // 2

        h3 = H - h2

        S2 = (W - w1) * h2

        S3 = (W - w1) * h3

        ans = min(ans, max(S1,S2,S3) - min(S1,S2,S3))



    print(ans)





    

    



if __name__ == "__main__":

    main()
def main():

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

    ans = float('inf')

    h1, h2, h3 = 0,0,0

    w1,w2,w1 = 0,0,0

    # 横3に切る場合

    h1 = H // 3

    h2 = H // 3

    h3 = H // 3

    if H % 3 == 1:

        h3 += 1

    elif H % 3 == 2:

        h2 += 1

        h3 += 1

    S = [h1*W,h2*W,h3*W]

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

    # 横2縦1に切る場合

    h1 = H // 2

    h2 = H // 2

    h3 = H

    if H % 2 == 1:

        h2 += 1

    for w in range(1,W):

        S = [h1*(W-w),h2*(W-w),h3*w]

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

    # 縦3に切る場合

    w1 = W // 3

    w2 = W // 3

    w3 = W // 3

    if W % 3 == 1:

        w3 += 1

    elif W % 3 == 2:

        w2 += 1

        w3 += 1

    S = [w1*H,w2*H,w3*H]

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



    # 縦1横2に切る場合

    w1 = W // 2

    w2 = W // 2

    w3 = W

    if W % 2 == 1:

        w2 += 1

    for h in range(1,H):

        S = [w1*(H-h),w2*(H-h),w3*h]

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



    print(ans)



if __name__ == "__main__":

    main()
def main():
    H, W = list(map(int, input().split()))
    S = H * W
    ans = float("inf")
    for h1 in range(1, H):
        S1 = h1 * W
        # 縦に分割する場合
        h2 = (H - h1) // 2
        S2 = h2 * W
        S3 = (H - h1 - h2) * W
        ans = min(ans, max(S1, S2, S3) - min(S1, S2, S3))
        # 横に分割する場合
        w2 = W // 2
        w3 = W - w2
        S2 = (H - h1) * w2
        S3 = (H - h1) * w3
        ans = min(ans, max(S1, S2, S3) - min(S1, S2, S3))
    for w1 in range(1, W):
        S1 = w1 * H
        # 横に分割する場合
        w2 = (W - w1) // 2
        S2 = w2 * H
        S3 = (W - w1 - w2) * H
        ans = min(ans, max(S1, S2, S3) - min(S1, S2, S3))
        # 縦に分割する場合
        h2 = H // 2
        h3 = H - h2
        S2 = (W - w1) * h2
        S3 = (W - w1) * h3
        ans = min(ans, max(S1, S2, S3) - min(S1, S2, S3))
    print(ans)


if __name__ == "__main__":
    main()

def main():
    H, W = list(map(int, input().split()))
    ans = float("inf")
    h1, h2, h3 = 0, 0, 0
    w1, w2, w1 = 0, 0, 0
    # 横3に切る場合
    h1 = H // 3
    h2 = H // 3
    h3 = H // 3
    if H % 3 == 1:
        h3 += 1
    elif H % 3 == 2:
        h2 += 1
        h3 += 1
    S = [h1 * W, h2 * W, h3 * W]
    ans = min(max(S) - min(S), ans)
    # 横2縦1に切る場合
    h1 = H // 2
    h2 = H // 2
    h3 = H
    if H % 2 == 1:
        h2 += 1
    for w in range(1, W):
        S = [h1 * (W - w), h2 * (W - w), h3 * w]
        ans = min(max(S) - min(S), ans)
    # 縦3に切る場合
    w1 = W // 3
    w2 = W // 3
    w3 = W // 3
    if W % 3 == 1:
        w3 += 1
    elif W % 3 == 2:
        w2 += 1
        w3 += 1
    S = [w1 * H, w2 * H, w3 * H]
    ans = min(max(S) - min(S), ans)
    # 縦1横2に切る場合
    w1 = W // 2
    w2 = W // 2
    w3 = W
    if W % 2 == 1:
        w2 += 1
    for h in range(1, H):
        S = [w1 * (H - h), w2 * (H - h), w3 * h]
        ans = min(max(S) - min(S), ans)
    print(ans)


if __name__ == "__main__":
    main()

-    S = H * W -    for h1 in range(1, H): -        S1 = h1 * W -        # 縦に分割する場合 -        h2 = (H - h1) // 2 -        S2 = h2 * W -        S3 = (H - h1 - h2) * W -        ans = min(ans, max(S1, S2, S3) - min(S1, S2, S3)) -        # 横に分割する場合 -        w2 = W // 2 -        w3 = W - w2 -        S2 = (H - h1) * w2 -        S3 = (H - h1) * w3 -        ans = min(ans, max(S1, S2, S3) - min(S1, S2, S3)) -    for w1 in range(1, W): -        S1 = w1 * H -        # 横に分割する場合 -        w2 = (W - w1) // 2 -        S2 = w2 * H -        S3 = (W - w1 - w2) * H -        ans = min(ans, max(S1, S2, S3) - min(S1, S2, S3)) -        # 縦に分割する場合 -        h2 = H // 2 -        h3 = H - h2 -        S2 = (W - w1) * h2 -        S3 = (W - w1) * h3 -        ans = min(ans, max(S1, S2, S3) - min(S1, S2, S3)) +    h1, h2, h3 = 0, 0, 0 +    w1, w2, w1 = 0, 0, 0 +    # 横3に切る場合 +    h1 = H // 3 +    h2 = H // 3 +    h3 = H // 3 +    if H % 3 == 1: +        h3 += 1 +    elif H % 3 == 2: +        h2 += 1 +        h3 += 1 +    S = [h1 * W, h2 * W, h3 * W] +    ans = min(max(S) - min(S), ans) +    # 横2縦1に切る場合 +    h1 = H // 2 +    h2 = H // 2 +    h3 = H +    if H % 2 == 1: +        h2 += 1 +    for w in range(1, W): +        S = [h1 * (W - w), h2 * (W - w), h3 * w] +        ans = min(max(S) - min(S), ans) +    # 縦3に切る場合 +    w1 = W // 3 +    w2 = W // 3 +    w3 = W // 3 +    if W % 3 == 1: +        w3 += 1 +    elif W % 3 == 2: +        w2 += 1 +        w3 += 1 +    S = [w1 * H, w2 * H, w3 * H] +    ans = min(max(S) - min(S), ans) +    # 縦1横2に切る場合 +    w1 = W // 2 +    w2 = W // 2 +    w3 = W +    if W % 2 == 1: +        w2 += 1 +    for h in range(1, H): +        S = [w1 * (H - h), w2 * (H - h), w3 * h] +        ans = min(max(S) - min(S), ans)