a, b = map(int, input().split())
c = 0

def provera():

    m1 = min(a, b, c)
    m2 = max(a, b, c)
    medijana = a + b + c - m1 - m2
    prosek = (a + b + c) / 3

    return prosek <= medijana

def resenje():

    provera()

    m3 = min(a, b)
    m4 = max(a, b)
    c = 2 * m4 - m3
    
    return c


print(resenje())