h, a = map(int, input().split()) ans = 0 x = 1 while h: ans += x h //= a x *= 2 print(ans)