H,A=map(int,input().split()) ANS=0 x=1 while H>0: ANS+=x H//=A x*=2 print(ANS)