# Arup Guha
# 12/3/2023
# Solution to 2023 UCF HS Online D2 Problem: No Way Out But Through

# Get input
toks = input().split()
n = int(toks[0])
base = int(toks[1])

res = 0

# Do base conversion.
while n > 0:

    # This is add 1 operation.
    res += (n%base)

    # This is multiply in reverse.
    n  = n // base

    # We don't count this one at the very end.
    if n > 0:
        res += 1

print(res)
