h, a = list(map(int, input().split()))

ans = 0
cnt = 1
while h > 0:
    ans += cnt
    h //= a
    cnt *= 2

print(ans)