def calcCandlesAndWaste(n, m):
    result = 0
    wastage = 0
    while(n>=1):
        wastage += n%m
        n = n/m
        result += n
    return (result, wastage)

def solve():
    result,wastage = 0,0
    line = str(raw_input()).split()
    a = int(line[0])
    b = int(line[1])
    while(a>=1):
        a, wastage = calcCandlesAndWaste(a,b)
        result += a
        a = wastage
        if(wastage < b):
            break
    print result+int(line[0])

solve()
