import re
def gcd(x, y):
	while(y):
		x, y = y, x % y
	return x
def lcm(x,y):
	return (x*y)/gcd(x,y)

def gen(nums,isRems):
	if isRems:
		count = 0
		if(nums[0] ==0 or int(nums[0]/nums[1])==0):
			return 0
	else: 
		count = nums[0]
	rems = 0
	while(nums[0]!=0 and nums[1]!=0):
		count = count + int(nums[0]/nums[1])
		rems = rems + (nums[0] % nums[1])
		nums[0] = int(nums[0]/nums[1])
	return count+gen([rems,nums[1]],True)

def main():
	# nums = []
	# num = int(raw_input())
	nums1 = raw_input().split(" ")
	# word1 = raw_input()
	# word2 = raw_input()
	# puzzles = raw_input().split(" ")
	nums1 = map(lambda x: int(x),nums1)
	#nums = [int(raw_input()) for t in range(0,3)]
	print gen(nums1,False)

if __name__ == "__main__":
	# while True:
	# 	main()
	main()