from math import floor, ceil

h, w = list(map(int, input().split(' ')))

result = []

if h%3 == 0 or w%3 == 0:

    print((0))

elif h<3 or w<3:

    if h<3 and w>=3:

        for i in range(1, w-1):

            x = i*h

            y = (w-i)*floor(h/2)

            z = (w-i)*ceil(h/2)

            result.append(max(x,y,z)-min(x,y,z))

            y = floor((w-i)/2)*h

            z = ceil((w-i)/2)*h

            result.append(max(x,y,z)-min(x,y,z))

        print((min(result)))

    elif h>=3 and w<3:

        for i in range(1, h-1):

            x = i*w

            y = (h-i)*floor(w/2)

            z = (h-i)*ceil(w/2)

            result.append(max(x,y,z)-min(x,y,z))

            y = floor((h-i)/2)*w

            z = ceil((h-i)/2)*w

            result.append(max(x,y,z)-min(x,y,z))

        print((min(result)))

    else:

        print((1))

else:

    for i in range(1, h-1):

        x = i*w

        y = (h-i)*floor(w/2)

        z = (h-i)*ceil(w/2)

        result.append(max(x,y,z)-min(x,y,z))

        y = floor((h-i)/2)*w

        z = ceil((h-i)/2)*w

        result.append(max(x,y,z)-min(x,y,z))

    for i in range(1, w-1):

        x = i*h

        y = (w-i)*floor(h/2)

        z = (w-i)*ceil(h/2)

        result.append(max(x,y,z)-min(x,y,z))

        y = floor((w-i)/2)*h

        z = ceil((w-i)/2)*h

        result.append(max(x,y,z)-min(x,y,z))

    print((min(result)))
def main():

    from math import floor, ceil

    h, w = list(map(int, input().split(' ')))

    result = []

    if h%3 == 0 or w%3 == 0:

        print((0))

    elif h<3 or w<3:

        if h<3 and w>=3:

            for i in range(1, w-1):

                x = i*h

                y = (w-i)*floor(h/2)

                z = (w-i)*ceil(h/2)

                result.append(max(x,y,z)-min(x,y,z))

                y = floor((w-i)/2)*h

                z = ceil((w-i)/2)*h

                result.append(max(x,y,z)-min(x,y,z))

            print((min(result)))

        elif h>=3 and w<3:

            for i in range(1, h-1):

                x = i*w

                y = (h-i)*floor(w/2)

                z = (h-i)*ceil(w/2)

                result.append(max(x,y,z)-min(x,y,z))

                y = floor((h-i)/2)*w

                z = ceil((h-i)/2)*w

                result.append(max(x,y,z)-min(x,y,z))

            print((min(result)))

        else:

            print((1))

    else:

        for i in range(1, h-1):

            x = i*w

            y = (h-i)*floor(w/2)

            z = (h-i)*ceil(w/2)

            result.append(max(x,y,z)-min(x,y,z))

            y = floor((h-i)/2)*w

            z = ceil((h-i)/2)*w

            result.append(max(x,y,z)-min(x,y,z))

        for i in range(1, w-1):

            x = i*h

            y = (w-i)*floor(h/2)

            z = (w-i)*ceil(h/2)

            result.append(max(x,y,z)-min(x,y,z))

            y = floor((w-i)/2)*h

            z = ceil((w-i)/2)*h

            result.append(max(x,y,z)-min(x,y,z))

        print((min(result)))

main()
from math import floor, ceil

h, w = list(map(int, input().split(" ")))
result = []
if h % 3 == 0 or w % 3 == 0:
    print((0))
elif h < 3 or w < 3:
    if h < 3 and w >= 3:
        for i in range(1, w - 1):
            x = i * h
            y = (w - i) * floor(h / 2)
            z = (w - i) * ceil(h / 2)
            result.append(max(x, y, z) - min(x, y, z))
            y = floor((w - i) / 2) * h
            z = ceil((w - i) / 2) * h
            result.append(max(x, y, z) - min(x, y, z))
        print((min(result)))
    elif h >= 3 and w < 3:
        for i in range(1, h - 1):
            x = i * w
            y = (h - i) * floor(w / 2)
            z = (h - i) * ceil(w / 2)
            result.append(max(x, y, z) - min(x, y, z))
            y = floor((h - i) / 2) * w
            z = ceil((h - i) / 2) * w
            result.append(max(x, y, z) - min(x, y, z))
        print((min(result)))
    else:
        print((1))
else:
    for i in range(1, h - 1):
        x = i * w
        y = (h - i) * floor(w / 2)
        z = (h - i) * ceil(w / 2)
        result.append(max(x, y, z) - min(x, y, z))
        y = floor((h - i) / 2) * w
        z = ceil((h - i) / 2) * w
        result.append(max(x, y, z) - min(x, y, z))
    for i in range(1, w - 1):
        x = i * h
        y = (w - i) * floor(h / 2)
        z = (w - i) * ceil(h / 2)
        result.append(max(x, y, z) - min(x, y, z))
        y = floor((w - i) / 2) * h
        z = ceil((w - i) / 2) * h
        result.append(max(x, y, z) - min(x, y, z))
    print((min(result)))

def main():
    from math import floor, ceil

    h, w = list(map(int, input().split(" ")))
    result = []
    if h % 3 == 0 or w % 3 == 0:
        print((0))
    elif h < 3 or w < 3:
        if h < 3 and w >= 3:
            for i in range(1, w - 1):
                x = i * h
                y = (w - i) * floor(h / 2)
                z = (w - i) * ceil(h / 2)
                result.append(max(x, y, z) - min(x, y, z))
                y = floor((w - i) / 2) * h
                z = ceil((w - i) / 2) * h
                result.append(max(x, y, z) - min(x, y, z))
            print((min(result)))
        elif h >= 3 and w < 3:
            for i in range(1, h - 1):
                x = i * w
                y = (h - i) * floor(w / 2)
                z = (h - i) * ceil(w / 2)
                result.append(max(x, y, z) - min(x, y, z))
                y = floor((h - i) / 2) * w
                z = ceil((h - i) / 2) * w
                result.append(max(x, y, z) - min(x, y, z))
            print((min(result)))
        else:
            print((1))
    else:
        for i in range(1, h - 1):
            x = i * w
            y = (h - i) * floor(w / 2)
            z = (h - i) * ceil(w / 2)
            result.append(max(x, y, z) - min(x, y, z))
            y = floor((h - i) / 2) * w
            z = ceil((h - i) / 2) * w
            result.append(max(x, y, z) - min(x, y, z))
        for i in range(1, w - 1):
            x = i * h
            y = (w - i) * floor(h / 2)
            z = (w - i) * ceil(h / 2)
            result.append(max(x, y, z) - min(x, y, z))
            y = floor((w - i) / 2) * h
            z = ceil((w - i) / 2) * h
            result.append(max(x, y, z) - min(x, y, z))
        print((min(result)))


main()

-from math import floor, ceil +def main(): +    from math import floor, ceil -h, w = list(map(int, input().split(" "))) -result = [] -if h % 3 == 0 or w % 3 == 0: -    print((0)) -elif h < 3 or w < 3: -    if h < 3 and w >= 3: +    h, w = list(map(int, input().split(" "))) +    result = [] +    if h % 3 == 0 or w % 3 == 0: +        print((0)) +    elif h < 3 or w < 3: +        if h < 3 and w >= 3: +            for i in range(1, w - 1): +                x = i * h +                y = (w - i) * floor(h / 2) +                z = (w - i) * ceil(h / 2) +                result.append(max(x, y, z) - min(x, y, z)) +                y = floor((w - i) / 2) * h +                z = ceil((w - i) / 2) * h +                result.append(max(x, y, z) - min(x, y, z)) +            print((min(result))) +        elif h >= 3 and w < 3: +            for i in range(1, h - 1): +                x = i * w +                y = (h - i) * floor(w / 2) +                z = (h - i) * ceil(w / 2) +                result.append(max(x, y, z) - min(x, y, z)) +                y = floor((h - i) / 2) * w +                z = ceil((h - i) / 2) * w +                result.append(max(x, y, z) - min(x, y, z)) +            print((min(result))) +        else: +            print((1)) +    else: +        for i in range(1, h - 1): +            x = i * w +            y = (h - i) * floor(w / 2) +            z = (h - i) * ceil(w / 2) +            result.append(max(x, y, z) - min(x, y, z)) +            y = floor((h - i) / 2) * w +            z = ceil((h - i) / 2) * w +            result.append(max(x, y, z) - min(x, y, z)) -    elif h >= 3 and w < 3: -        for i in range(1, h - 1): -            x = i * w -            y = (h - i) * floor(w / 2) -            z = (h - i) * ceil(w / 2) -            result.append(max(x, y, z) - min(x, y, z)) -            y = floor((h - i) / 2) * w -            z = ceil((h - i) / 2) * w -            result.append(max(x, y, z) - min(x, y, z)) -        print((min(result))) -    else: -        print((1)) -else: -    for i in range(1, h - 1): -        x = i * w -        y = (h - i) * floor(w / 2) -        z = (h - i) * ceil(w / 2) -        result.append(max(x, y, z) - min(x, y, z)) -        y = floor((h - i) / 2) * w -        z = ceil((h - i) / 2) * w -        result.append(max(x, y, z) - min(x, y, z)) -    for i in range(1, w - 1): -        x = i * h -        y = (w - i) * floor(h / 2) -        z = (w - i) * ceil(h / 2) -        result.append(max(x, y, z) - min(x, y, z)) -        y = floor((w - i) / 2) * h -        z = ceil((w - i) / 2) * h -        result.append(max(x, y, z) - min(x, y, z)) -    print((min(result))) + + +main()