def prosek(a, b, c):
    return (a+b+c)/3
def medijana(a, b, c):
    return a+b+c-min(a, b, c) - max(a, b, c)
def lepa(a, b, c):
    if prosek(a, b, c) <= medijana(a, b, c):
        return True
    else:
        return False
a, b = [int(x) for x in input().split()]
l = 1
r = 1000000000000000000
c = 0
while l < r:
    c = (l+r)//2
    if lepa(a, b, c) != True:
        r = c
    else:
        if lepa(a, b, c+1) != True:
            break
        else:
            l = c
print(c)