# coding: utf-8

# Your code here!

h,w = [int(i) for i in input().split()]



def once(h,w):

    res = 10**9

    if h > 1:

        a,b = h//2*w, (h-h//2)*w

        res = abs(a-b)

    if w > 1:

        c,d = w//2*h, (w-w//2)*h

        if abs(c-d) < res:

            a,b = c,d

    return a,b    





def hsaki(h,w):

    res = 10**9

    for i in range(1,h):

        p1 = i*w

        p2,p3 = once(h-i,w)

        a = max(p1,p2,p3) - min(p1,p2,p3) 

        res = min(res, a)

#        print(p1,p2,p3)

    return res



#print(hsaki(h,w), hsaki(w,h))



ans = min(hsaki(h,w), hsaki(w,h))

print(ans)
# coding: utf-8

# Your code here!

import sys

read = sys.stdin.read

readline = sys.stdin.readline



h,w = list(map(int,readline().split()))





def f(h,w):

    ans = h*w

    for i in range(1,h):

        v1 = i*w

        if (h-i)%2==0 or w%2 == 0:

            v2 = (h-i)*w//2

        else:

            v2 = max((h-i)//2*w,w//2*(h-i))

        v3 = (h-i)*w - v2

        

        ans = min(ans,max(v1,v2,v3)-min(v1,v2,v3))

        #print(i,h,w,v1,v2,v3,ans)

    return ans



print((min(f(h,w),f(w,h))))









# coding: utf-8
# Your code here!
h, w = [int(i) for i in input().split()]


def once(h, w):
    res = 10**9
    if h > 1:
        a, b = h // 2 * w, (h - h // 2) * w
        res = abs(a - b)
    if w > 1:
        c, d = w // 2 * h, (w - w // 2) * h
        if abs(c - d) < res:
            a, b = c, d
    return a, b


def hsaki(h, w):
    res = 10**9
    for i in range(1, h):
        p1 = i * w
        p2, p3 = once(h - i, w)
        a = max(p1, p2, p3) - min(p1, p2, p3)
        res = min(res, a)
    #        print(p1,p2,p3)
    return res


# print(hsaki(h,w), hsaki(w,h))
ans = min(hsaki(h, w), hsaki(w, h))
print(ans)

# coding: utf-8
# Your code here!
import sys

read = sys.stdin.read
readline = sys.stdin.readline
h, w = list(map(int, readline().split()))


def f(h, w):
    ans = h * w
    for i in range(1, h):
        v1 = i * w
        if (h - i) % 2 == 0 or w % 2 == 0:
            v2 = (h - i) * w // 2
        else:
            v2 = max((h - i) // 2 * w, w // 2 * (h - i))
        v3 = (h - i) * w - v2
        ans = min(ans, max(v1, v2, v3) - min(v1, v2, v3))
        # print(i,h,w,v1,v2,v3,ans)
    return ans


print((min(f(h, w), f(w, h))))

-h, w = [int(i) for i in input().split()] +import sys + +read = sys.stdin.read +readline = sys.stdin.readline +h, w = list(map(int, readline().split())) -def once(h, w): -    res = 10**9 -    if h > 1: -        a, b = h // 2 * w, (h - h // 2) * w -        res = abs(a - b) -    if w > 1: -        c, d = w // 2 * h, (w - w // 2) * h -        if abs(c - d) < res: -            a, b = c, d -    return a, b +def f(h, w): +    ans = h * w +    for i in range(1, h): +        v1 = i * w +        if (h - i) % 2 == 0 or w % 2 == 0: +            v2 = (h - i) * w // 2 +        else: +            v2 = max((h - i) // 2 * w, w // 2 * (h - i)) +        v3 = (h - i) * w - v2 +        ans = min(ans, max(v1, v2, v3) - min(v1, v2, v3)) +        # print(i,h,w,v1,v2,v3,ans) +    return ans -def hsaki(h, w): -    res = 10**9 -    for i in range(1, h): -        p1 = i * w -        p2, p3 = once(h - i, w) -        a = max(p1, p2, p3) - min(p1, p2, p3) -        res = min(res, a) -    #        print(p1,p2,p3) -    return res - - -# print(hsaki(h,w), hsaki(w,h)) -ans = min(hsaki(h, w), hsaki(w, h)) -print(ans) +print((min(f(h, w), f(w, h))))