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