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