H, A = map(int, input().split())
ans = 0
cnt = 1
while H>0:
    H //= A
    ans += cnt
    cnt *= 2
print(ans)