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