H, A = gets.split.map(&:to_i) ans = 0 h = H num = 1 while h > 0 ans += num h /= A num *= 2 end puts ans