[a, b] = map(int, raw_input().split())

total = 0
remainder = 0
while a != 0:
	total += a
	remainder += a % b
	a = a / b
	if a == 0:
		temp = remainder % b
		a = remainder / b
		remainder = temp

print total
