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