H,A = map(int, input().split()) N = 0 while H > 0: H = H // A N += 1 #print(f"{N=}") ans = 0 for i in range(0,N): ans += 2**i #print(f"{ans=}") print(ans)