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