h,a=map(int,input().split()) l=[h] while l[-1]!=0: l.append(l[-1]//a) print(2**(len(l)-1)-1)