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