import heapq from collections import defaultdict n, a = map(int, input().split()) ans = 0 hp = [] heapq.heappush(hp, [-n, 1]) # 降順にするため負値 while(len(hp) > 0): val, cnt = heapq.heappop(hp) val *= -1 ans += cnt n_val = val // a if n_val > 0: heapq.heappush(hp, [-n_val, cnt*2]) print(ans)