h,a=map(int,input().split()) c=1 ans=0 while h: ans+=c h//=a c*=2 print(ans)