h, a = map(int, input().split()) b = 0 c = 1 for i in range(h): if h > 0: b += c h = h // a c *= 2 if h <= 0 and c == 0: break print(b)