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