H , A = map(int,input().split()) B = [1] for i in range (0,H): H = H // A if H == 0: # print(B) print(sum(B)) break else: B.append(B[-1] * 2)