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