h, a = gets.chomp.split.map{|e| e.to_i} res = 0 cnt = 1 while h > 0 h /= a res += cnt cnt *= 2 end puts res