#!/usr/bin/env python3

#%% for atcoder uniittest use

import sys

input= lambda: sys.stdin.readline().rstrip()

sys.setrecursionlimit(10**9)

def pin(type=int):return list(map(type,input().split()))

def tupin(t=int):return tuple(pin(t))

def lispin(t=int):return list(pin(t))

#%%code



from fractions import gcd

def resolve():

    H,W=pin()

    #たてに切る

    hori=0 if W%3==0 else H

    #よこにきる

    vert=0 if H%3==0 else W

    #たてに切った後よこ

    sp1=H*W

    for w in range(W):

        g=H*(w+1)

        #b>=rとする

        t=(H+1)//2

        b=t*(W-w-1)

        r=(H//2)*(W-w-1)

        sp1=min(sp1,max(g,b,r)-min(g,b,r))

    #横に切った後たて

    sp2=H*W

    for h in range(H):

        g=W*(h+1)

        #b>=rとする

        t=(W+1)//2

        b=t*(H-h-1)

        r=(W//2)*(H-h-1)

        sp2=min(sp2,max(g,b,r)-min(g,b,r))

    #上4つの最小 間に合ってほしいねぇ

    print((min(hori,vert,sp1,sp2)))

#%%submit!

resolve()
#!/usr/bin/env python3

#%% for atcoder uniittest use

import sys

input= lambda: sys.stdin.readline().rstrip()

def pin(type=int):return list(map(type,input().split()))

def tupin(t=int):return tuple(pin(t))

#%%code

def resolve():

    H,W=pin()



    if H%3==0 or W%3==0:

        print((0))

        return

    #     

    ans=min(H,W)

    for i in range(1,H):

        yoko=W*i

        a=W//2*(H-i)

        b=W*H-yoko-a

        

        t=(max(yoko,a,b)-min(yoko,a,b))

        ans=min(t,ans)



    for j in range(1,W):

        yoko=H*j

        a=(H//2)*(W-j)

        b=W*H-yoko-a

        

        t=(max(yoko,a,b)-min(yoko,a,b))

        ans=min(t,ans)

    print(ans)

#%%submit!

resolve()
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys

input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)


def pin(type=int):
    return list(map(type, input().split()))


def tupin(t=int):
    return tuple(pin(t))


def lispin(t=int):
    return list(pin(t))


#%%code
from fractions import gcd


def resolve():
    H, W = pin()
    # たてに切る
    hori = 0 if W % 3 == 0 else H
    # よこにきる
    vert = 0 if H % 3 == 0 else W
    # たてに切った後よこ
    sp1 = H * W
    for w in range(W):
        g = H * (w + 1)
        # b>=rとする
        t = (H + 1) // 2
        b = t * (W - w - 1)
        r = (H // 2) * (W - w - 1)
        sp1 = min(sp1, max(g, b, r) - min(g, b, r))
    # 横に切った後たて
    sp2 = H * W
    for h in range(H):
        g = W * (h + 1)
        # b>=rとする
        t = (W + 1) // 2
        b = t * (H - h - 1)
        r = (W // 2) * (H - h - 1)
        sp2 = min(sp2, max(g, b, r) - min(g, b, r))
    # 上4つの最小 間に合ってほしいねぇ
    print((min(hori, vert, sp1, sp2)))


#%%submit!
resolve()

#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys

input = lambda: sys.stdin.readline().rstrip()


def pin(type=int):
    return list(map(type, input().split()))


def tupin(t=int):
    return tuple(pin(t))


#%%code
def resolve():
    H, W = pin()
    if H % 3 == 0 or W % 3 == 0:
        print((0))
        return
    #
    ans = min(H, W)
    for i in range(1, H):
        yoko = W * i
        a = W // 2 * (H - i)
        b = W * H - yoko - a
        t = max(yoko, a, b) - min(yoko, a, b)
        ans = min(t, ans)
    for j in range(1, W):
        yoko = H * j
        a = (H // 2) * (W - j)
        b = W * H - yoko - a
        t = max(yoko, a, b) - min(yoko, a, b)
        ans = min(t, ans)
    print(ans)


#%%submit!
resolve()

-sys.setrecursionlimit(10**9) -def lispin(t=int): -    return list(pin(t)) - - -from fractions import gcd - - -    # たてに切る -    hori = 0 if W % 3 == 0 else H -    # よこにきる -    vert = 0 if H % 3 == 0 else W -    # たてに切った後よこ -    sp1 = H * W -    for w in range(W): -        g = H * (w + 1) -        # b>=rとする -        t = (H + 1) // 2 -        b = t * (W - w - 1) -        r = (H // 2) * (W - w - 1) -        sp1 = min(sp1, max(g, b, r) - min(g, b, r)) -    # 横に切った後たて -    sp2 = H * W -    for h in range(H): -        g = W * (h + 1) -        # b>=rとする -        t = (W + 1) // 2 -        b = t * (H - h - 1) -        r = (W // 2) * (H - h - 1) -        sp2 = min(sp2, max(g, b, r) - min(g, b, r)) -    # 上4つの最小 間に合ってほしいねぇ -    print((min(hori, vert, sp1, sp2))) +    if H % 3 == 0 or W % 3 == 0: +        print((0)) +        return +    # +    ans = min(H, W) +    for i in range(1, H): +        yoko = W * i +        a = W // 2 * (H - i) +        b = W * H - yoko - a +        t = max(yoko, a, b) - min(yoko, a, b) +        ans = min(t, ans) +    for j in range(1, W): +        yoko = H * j +        a = (H // 2) * (W - j) +        b = W * H - yoko - a +        t = max(yoko, a, b) - min(yoko, a, b) +        ans = min(t, ans) +    print(ans)