Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.

Vasily has a candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make b went out candles into a new candle. As a result, this new candle can be used like any other new candle.

Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number.


-----Input-----

The single line contains two integers, a and b (1 ≤ a ≤ 1000; 2 ≤ b ≤ 1000).


-----Output-----

Print a single integer — the number of hours Vasily can light up the room for.


-----Examples-----
Input
4 2

Output
7

Input
6 3

Output
8



-----Note-----

Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours.

Source: codeforces | Difficulty: EASY
Tags: Implementation


Solutions:
(a, b) = map(int, input().split())
sums = a
while a >= b:
	div = a // b
	sums = sums + div
	k = a % b
	a = div + k
print(sums)


(n, m) = map(int, input().split())
d = 1
while d <= n:
	if d % m == 0:
		n += 1
	d += 1
print(d - 1)


(a, b) = list(map(int, input().split()))
h = a
while int(a / b) >= 1:
	h = h + int(a / b)
	a = int(a / b) + a % b
print(h)


var = input()
(n, m) = var.split()
n = int(n)
m = int(m)
old_m = m
while n >= m:
	n += 1
	m += old_m
print(n)


(a, b) = map(int, input().split())
count = 0
answer = 0
while True:
	if a > 0:
		a -= 1
		count += 1
		answer += 1
	if count == b:
		count = 0
		a += 1
	if a == 0:
		break
print(answer)


(a, b) = map(int, input().split())
sum = a
while a >= b:
	sum += a // b
	a = a // b + a % b
print(sum)


(n, m) = map(int, input().split())
print(n + (n - 1) // (m - 1))


(a, b) = map(int, input().split())
t = 0
candles = a
old = 0
while candles > 0 and old < b:
	t = t + 1
	candles = candles - 1
	old = old + 1
	if old >= b:
		old = 0
		candles = candles + 1
print(t)


(a, b) = map(int, input().split())
h = a
m = 0
while 1:
	c = a // b
	a = c + a % b
	h = h + c
	if a < b:
		break
print(h)


(a, b) = map(int, input().split())
h = a
c = 0
while a + c >= b:
	d = (a + c) % b
	a = int((a + c) / b)
	h += a
	c = d
print(h)


(a, b) = map(int, input().split())
hours = a
while a >= b:
	if a // b > 0:
		hours += a // b
		a = a // b + a % b
print(hours)


(a, b) = input().split()
a = int(a)
b = int(b)
ans = a
r = 0
while a > 0:
	r += a
	a = r // b
	r = r % b
	ans += a
print(ans)


(candles, parts) = map(int, input().split())
hours = candles
spare = 0
while candles > 0:
	new_candles = (candles + spare) // parts
	spare = (candles + spare) % parts
	candles = new_candles
	hours += candles
print(hours)


(a, b) = map(int, input().split())
s = a
while a >= b:
	s += a // b
	a = a // b + a % b
print(s)


(n, k) = map(int, input().split())
ans = n
ogr = 0
while n + ogr >= k:
	(n, ogr) = ((n + ogr) // k, (n + ogr) % k)
	ans += n
print(ans)


(a, b) = map(int, input().split())
out = a
while a >= b:
	out += a // b
	a = a // b + a % b
print(out)


def main():
	(a, b) = map(int, input().split())
	term = a // b
	rem = a % b
	hours = a + term
	collect = [hours]
	term += rem
	while term >= b:
		rem = term % b
		term = term // b
		collect.append(term)
		term += rem
	print(sum(collect))
main()


(n, m) = input().split()
n = int(n)
m = int(m)
anse = n
while True:
	if (n - n % m) % m == 0 and n > 1:
		anse = anse + n / m
		n = n / m
	else:
		break
print(int(anse))


(a, b) = map(int, input().split())
days = 0
while a - b >= 0:
	a = a - b + 1
	days = days + b
print(days + a)


(n, x) = map(int, input().split())
c = 0
s = 0
while n > 0:
	c += n
	s += n % x
	n = n // x + s // x
	s = s % x
print(c)


ab = input().split()
a = int(ab[0])
b = int(ab[1])
ans = a
while a // b != 0:
	ans += a // b
	a = a // b + a % b
print(ans)


(a, b) = map(int, input().split())
output = b * ((a - b) // (b - 1) + 1) + (a - b) % (b - 1) + 1
print(output)


(a, b) = map(int, input().split())
total_hours = a
candles_out = a
while candles_out >= b:
	candles_out += 1 - b
	total_hours += 1
print(total_hours)


import sys
candles = sys.stdin.readline().strip().split(' ')
a = int(candles[0])
b = int(candles[1])
c = 0
while a >= b:
	c += b
	a -= b
	a += 1
print(c + a)


(a, b) = input().split()
(a, b) = (int(a), int(b))
x = 0
while a >= b:
	x += a - a % b
	a = a // b + a % b
x += a
print(x)


(a, b) = map(int, input().split())
total = a
while a >= b:
	total += a // b
	a = a // b + a % b
print(total)


(a, b) = list(map(int, input().split()))
n = 0
f = 0
while a > 0:
	a -= 1
	n += 1
	f += 1
	if f >= b:
		f -= b
		a += 1
print(n)


import sys
(a, b) = [int(i) for i in sys.stdin.readline().rstrip().split()]
hours = 0
went_out = 0
while a > 0:
	went_out += 1
	if went_out >= b:
		went_out -= b
		a += 1
	a -= 1
	hours += 1
print(hours)


def main():
	(a, b) = [int(x) for x in input().split()]
	counter = a
	while a >= b:
		new_candles = a // b
		counter = counter + new_candles
		temp = a % b
		a = temp + new_candles
	print(counter)
main()


(n, m) = map(int, input().split())
i = 0
wear_out = 0
while n > 0:
	i += 1
	n -= 1
	wear_out += 1
	if wear_out == m:
		n += 1
		wear_out = 0
print(i)


(n, k) = map(int, input().split())
ans = n
r = 0
while n > 0:
	n = n + r
	r = n % k
	n = n // k
	ans = ans + n
print(ans)


(a, b) = [int(x) for x in input().split()]
h = 0
while a >= b:
	h += b
	a += 1 - b
print(h + a)


(a, b) = map(int, input().split())
c = 0
while a > 0:
	a -= 1
	c += 1
	if c % b == 0:
		a += 1
print(c)


(s, n) = map(int, input().split())
print((s - 1) // (n - 1) + s)


import sys
sys.setrecursionlimit(280000)
(a, b) = map(int, input().split())
ans = 0
dead = a
while a >= b:
	ans += a - a % b
	dx = a - a % b
	a -= dx
	a += dx // b
print(ans + a)


(candles, conversion) = map(int, input().split())
sum = candles
remains = 0
while candles >= conversion:
	remains = candles % conversion
	candles = candles // conversion
	sum += candles
	candles += remains
print(sum)


(a, b) = tuple(input().split(' '))
a = int(a)
b = int(b)
used = 0
hours = 0
while a != 0:
	a -= 1
	hours += 1
	used += 1
	if used % b == 0:
		used = 0
		a += 1
print(hours)


(a, b) = [int(i) for i in input().split()]
c = a // b
d = a % b
while c != 0:
	a += c
	c1 = c + d
	c = (c + d) // b
	if c1 < b:
		d = 0
	else:
		d = c1 % b
print(a)


(n, m) = map(int, input().split(' '))
ans = 0
i = n
while i >= m:
	localans = i // m
	i = localans + i % m
	ans += localans
print(ans + n)


(a, b) = map(int, input().split(' '))
s = 0
burnt = 0
while a > 0:
	s += a
	burnt += a
	a = burnt // b
	burnt %= b
print(s)


s = input()
l = s.split()
n = int(l[0])
m = int(l[1])
a = n
while n // m != 0:
	k = n - m * (n // m)
	n = n // m
	a += n
	n += k
print(a)


(a, b) = list(map(int, input().split(' ')))
(l, h) = (0, 0)
while a > 0:
	h += a
	l += a
	a = l // b
	l -= l // b * b
print(h)


(a, b) = map(int, input().split())
k = a
ost = 0
while a >= b:
	ost = a % b
	a = a // b
	k = k + a
	a = a + ost
print(k)


(a, b) = map(int, input().split())
count = 0
while a >= 1:
	count += 1
	a -= 1
	if count % b == 0:
		a += 1
print(count)


(a, b) = map(int, input().split())
(h, r) = (a, 0)
while a:
	r += a % b
	a = a // b
	h += a
	if r >= b:
		h += r // b
		r = r % b
		a += 1
print(h)


import sys

def main():
	(a, b) = map(int, sys.stdin.readline().split())
	h = 0
	count = 0
	while a > 0:
		a -= 1
		h += 1
		count += 1
		if count == b:
			a += 1
			count *= 0
	sys.stdout.write(f'{h}')
main()


(n, m) = map(int, input().split())
count = n
while n >= m:
	count += n // m
	n = n // m + n % m
print(int(count))


(X, Y) = list(map(int, input().split()))
newCandels = 0
while X >= Y:
	newCandels += Y
	X -= Y
	X = X + 1
print(X + newCandels)


(a, b) = map(int, input().split())
t = 0
while a >= b:
	a -= b - 1
	t += b
t += a
print(t)


(n, l) = input().split()
n = int(n)
l = int(l)
ans = n
used = n
unuse = 0
while used + unuse >= l:
	use = (used + unuse) // l
	ans += use
	unuse = (used + unuse) % l
	used = use
print(ans)


(a, b) = input().split()
a = int(a)
b = int(b)
rez = a
while a > 0:
	rez += int(a / b)
	a = int(a / b) + a % b
	if int(a / b) == 0:
		break
print(rez)


(a, b) = map(int, input().split())
res = a
h = 0
while a > 0:
	t = (a + h) // b
	h = (a + h) % b
	a = t
	res += a
print(res)


(n, m) = [int(i) for i in input().split()]
c = n
d = 0
while True:
	x = n // m
	c += x
	n = x + n % m
	if n < m:
		break
print(c)


(a, b) = map(int, input().split())
ans = 0
tt = a
while a >= b:
	m = a // b
	ans += m
	t = a % b
	a = m + t
print(ans + tt)


(a, b) = [int(s) for s in input().split()]
burned = 0
r = 0
while a > 0:
	burned += a
	if r > 0:
		a += r
	(a, r) = (a // b, a % b)
print(burned)


(a, b) = map(int, input().split())
ans = 0
while a >= b:
	ans = ans + b
	a = a - b + 1
print(ans + a)


x = input()
(a, b) = (int(x.split()[0]), int(x.split()[1]))
total = a
s = a
div = a // b
mod = 0
while div > 0:
	div = s // b
	mod = s % b
	total += div
	s = div + mod
print(total)


(a, b) = map(int, input().split())
candles = a
leftout = a
while leftout >= b:
	candles += leftout // b
	leftout = leftout % b + leftout // b
print(candles)


(a, b) = map(int, input().split())
i = a
while a // b > 0:
	i = i + a // b
	a = a // b + a % b
print(i)


(t, c) = map(int, input().split())
b = t
while b >= c:
	d = b // c
	t += d
	b = b % c + d
print(t)


(a, b) = map(int, input().split())
if 1 <= a <= 1000 and 2 <= b <= 1000:
	i = 0
	j = 1
	c = 0
	while a > 0:
		i += 1
		a -= 1
		c += 1
		if i == b * j and c % b == 0:
			j += 1
			a += 1
			c -= b
	print(i)


(c, t) = map(int, input().split())
s = c
while c >= 1:
	c = c / t
	s = s + c
print(int(s // 1))


a = list(map(int, input().split(' ')))
time = 0
used = 0
while True:
	time += a[0]
	used += a[0]
	a[0] = 0
	if used >= a[1]:
		a[0] += int(used / a[1])
		used = used % a[1]
	else:
		break
print(time)


import math
(a, b) = list(map(int, input().split()))
hrs = a
while a >= b:
	a = a / b
	hrs += a
if a / b + hrs >= math.floor(hrs) + 1:
	print(math.floor(a / b + hrs))
else:
	print(math.floor(hrs))


(a, b) = list(map(int, input().split()))
count = 0
while a >= b:
	r = a % b
	new = (a - r) // b
	count = count + (a - r)
	a = r + new
count = count + a
print(count)


(a, b) = map(int, input().split())
r = a
while a > a % b:
	r += a // b
	a = a // b + a % b
print(r)


(q, w) = map(int, input().split())
s = q
e = 0
while q // w > 0:
	s += q // w
	q = q // w + q % w
print(s)


def main():
	(a, b) = map(int, input().split())
	r = 0
	h = 0
	n = 0
	r = 0
	while a >= 1:
		h = a + h
		x = a
		a = (x + r) // b
		r = (x + r) % b
	print(h)
main()


(a, b) = [int(i) for i in input().split()]
c = 0
i = 1
while a != 0:
	if i % b == 0:
		a += 1
	a -= 1
	c += 1
	i += 1
print(c)


import math

def main():
	i = input().split()
	a = int(i[0])
	b = int(i[1])
	x = a
	e = 0
	while int(a / b + e) > 0:
		t = a / b + e
		e = t - int(t)
		a = int(t)
		x += a
	print(x)
main()


(a, b) = map(int, input().split())
k = a
while a >= b:
	di = a // b
	r = a % b
	k += di
	a = di + r
print(k)


(a, b) = list(map(int, input().split()))
burnt = a
partially_burnt = 0
hours = a
while burnt > b - 1:
	partially_burnt = burnt % b
	hours += burnt // b
	burnt = burnt // b + partially_burnt
print(int(hours))


(a, b) = map(int, input().split())
count_h = a
while a >= b:
	a -= b
	a += 1
	count_h += 1
print(count_h)


(a, b) = map(int, input().split())
h = a
while a >= b:
	h += a // b
	a = a // b + a % b
print(h)


(a, b) = map(int, input().split())
temp = 0
hr = 0
while a > 0:
	hr += 1
	a -= 1
	temp += 1
	if temp >= b:
		temp -= b
		a += 1
print(hr)


(a, b) = list(map(int, input().strip().split()))
count = a
while a // b >= 1:
	count += a // b
	a = a // b + a % b
print(count)


(a, ratio) = map(int, input().split())
m = a
tot = a
while tot >= ratio > 0:
	m = m + tot // ratio
	tot = tot // ratio + tot % ratio
print(m)


(a, b) = (int(i) for i in input().split())
hours = 0
old = 0
while a > 0:
	hours += 1
	a -= 1
	old += 1
	if old == b:
		a += 1
		old = 0
print(hours)


(a, b) = map(int, input().split())
time = a
while not a < b:
	time += a // b
	a = a // b + a % b
print(time)


(a, b) = list(map(int, input().split()))
hours = 0
x = a
hours += a
while a >= b:
	x = a // b
	hours += x
	y = a % b
	a = x + y
print(hours)


(a, b) = map(int, input().split())
import math
print(math.ceil(a * b / (b - 1)) - 1)


(a, b) = map(int, input().split())
ans = a
temp = a
left = a % b
while temp >= b:
	ans += temp // b
	temp = temp // b + temp % b
print(ans)


import sys

def ii():
	return sys.stdin.readline().strip()

def idata():
	return [int(x) for x in ii().split()]

def solve_of_problem():
	(a, b) = idata()
	ans = 0
	while a >= b:
		c = a // b
		ans += b * c
		a -= (b - 1) * c
	print(ans + a)
	return
for ______ in range(1):
	solve_of_problem()


(a, b) = map(int, input().split())
result = 0
left = a * b
while left >= b:
	result += left // b
	left = left % b + left // b
print(result)


(a, b) = (int(i) for i in input().split())
time = a
while True:
	time += a // b
	ost = a % b + a // b
	a = ost
	if a < b:
		break
print(time)


(a, b) = map(int, input().split())
i = 1
c = 0
while True:
	if i % b != 0:
		a -= 1
	c += 1
	if a == 0:
		break
	i += 1
print(c)


(a, b) = map(int, input().split())
out = 0
total = 0
while a > 0:
	total += a
	out += a
	a = 0
	a += int(out / b)
	out -= a * b
print(total)


(n, m) = (int(i) for i in input().split())
d = 0
while d != n:
	d += 1
	if d % m == 0:
		n += 1
print(d)


(a, b) = map(int, input().split())
i = 0
j = a
ans = a
while j >= b:
	now = j // b
	ans += now
	j %= b
	j += now
print(ans)


(a, b) = (int(x) for x in input().split())
hours = a
while a // b:
	hours += a // b
	a = a // b + a % b
print(hours)


(a, b) = list(map(int, input().strip().split(' ')))
currc = a
rem = 0
ans = 0
while 1:
	ans += currc
	rem += currc
	currc = 0
	if rem >= b:
		currc += rem // b
		rem = rem % b
	else:
		break
print(ans)


(a, b) = map(int, input().split())
result = a
res = a
while res // b != 0:
	mod = res % b
	res //= b
	result += res
	res += mod
print(result)


(n, m) = map(int, input().split())
cnt = 0
cnt += n
while int(n / m) != 0:
	cnt += int(n / m)
	n = int(n / m) + n % m
print(cnt)


(a, b) = [int(i) for i in input().split()]
n = 0
n += a
resi = a % b
c = int((a - resi) / b)
while c >= 1:
	n += c
	a = c + resi
	resi = a % b
	c = int((a - resi) / b)
print(n)


a_b = [int(x) for x in input().split()]
a = a_b[0]
b = a_b[1]
print(a + (a - 1) // (b - 1))


(n, l) = [int(i) for i in input().split()]
counter = n
rem = n // l
while rem > 0:
	counter += rem
	n = n % l + n // l
	rem = n // l
print(counter)


(a, b) = map(int, input().split())
sum = a
p = 0
y = 0
while a >= b:
	y = a % b
	a = int(a / b)
	sum = sum + a
	a = a + y
print(sum)


(n, m) = map(int, input().split())
s = 0
while n >= m:
	s += n - n % m
	n = sum(divmod(n, m))
print(s + n)


(a, b) = map(int, input().split())
i = 0
s = b
while a > 0:
	a -= 1
	i += 1
	if i == b:
		a += 1
		b += s
print(i)


(a, b) = map(int, input().split())
c = a
x = a // b
y = a % b
c += x
while x != 0:
	i = x + y
	x = i // b
	y = i % b + x
	c += x
	while y >= b:
		x = y // b
		y = y % b + x
		c += x
	break
print(c)


(n, k) = map(int, input().split())
print(n + (n - 1) // (k - 1))


(a, b) = map(int, input().split())
w = a
q = 0
while a >= b:
	w += a // b
	q = a % b
	a = a // b + q
print(w)


(a, b) = map(int, input().split())
hourslit = a
oldcandles = a
while oldcandles >= b:
	q = oldcandles // b
	oldcandles -= q * (b - 1)
	hourslit += q
print(hourslit)


import re
input_list = re.findall('[0-9]+', input())
a = int(input_list[0])
b = int(input_list[1])
answer = a
while a >= b:
	answer += int(a / b)
	a = int(a / b) + int(a % b)
print(int(answer))


(n, m) = map(int, input().split())
x = n
while int(n):
	n = n / m
	x += n
print(int(x))


(a, b) = map(int, input().split())
ans = (a * b - 1) // (b - 1)
print(ans)


a = list(map(int, input().split()))
can = a[0]
hou = 0
while True:
	can -= 1
	hou += 1
	if hou % a[1] == 0:
		can += 1
	if can == 0:
		break
print(hou)


import sys
local_launch = False
try:
	open('LOCAL').read()
	local_launch = True
except:
	pass
input_data = open('INPUT.txt').read() if local_launch else sys.stdin.read()
done = {'i': 0}
tokens = input_data.split()

def next_token():
	result = tokens[done['i']]
	done['i'] += 1
	return result

def next_int():
	return int(next_token())

def next_str():
	return next_token()
a = next_int()
b = next_int()
candles = a
burned = 0
parts = 0
while candles > 0:
	burned += candles
	parts += candles
	candles = parts // b
	parts %= b
print(burned)


(a, b) = tuple(map(int, input().split()))
spent = a
hours = a
while spent >= b:
	spent -= b
	hours += 1
	spent += 1
print(hours)


(a, b) = map(int, input().split())
candles = a
while a // b > 0:
	candles += a // b
	a = a // b + a % b
print(candles)


(a, b) = map(int, input().split())
th = 0
nc = 0
while a:
	a -= 1
	nc += 1
	th += 1
	if nc == b:
		a += 1
		nc = 0
print(th)


(x, y) = map(int, input().split())
print(x + (x - 1) // (y - 1))


temp = input().split()
a = int(temp[0])
b = int(temp[1])
h = 0
p = 0
while a > 0:
	a -= 1
	p += 1
	if p == b:
		a += 1
		p = 0
	h += 1
print(h)


(p, q) = map(int, input().split())
z = 0
t = 0
while p != 0:
	z += p
	t += p % q
	p //= q
	if t >= q:
		p += t // q
		t %= q
print(z)


s = input()
s = s.split()
a = int(s[0])
b = int(s[1])
hr = a
j = a
while True:
	if j < b:
		break
	else:
		j = j - b + 1
		hr = hr + 1
print(hr)


line = input().split(' ')
a = int(line[0])
b = int(line[1])
c = a
cnt = 0
while c > 0:
	c -= 1
	cnt += 1
	if cnt % b == 0:
		c += 1
print(cnt)


import sys
(a, b) = map(int, sys.stdin.readline().split())
hour = 0
wentout = 0
while a > 0:
	hour += a
	wentout += a
	if wentout >= b:
		a = int(wentout / b)
		wentout -= a * b
	else:
		break
print(hour)


(a, b) = map(int, input().split())
ans = 0
cnt = 0
while a > 0:
	ans = ans + 1
	a = a - 1
	cnt = cnt + 1
	if cnt == b:
		a = a + 1
		cnt = 0
print(ans)


(n, k) = input().split()
n = int(n)
k = int(k)
count = n
while n >= k:
	temp = n // k + n % k
	count += n // k
	n = temp
print(count)


(a, b) = map(int, input().split())
hour = 0
while a != 0:
	hour += 1
	a -= 1
	if hour % b == 0:
		a += 1
print(hour)


a = input().split()
(ans, w) = (0, 0)
for i in range(int(a[0])):
	ans = ans + 1
	w = w + 1
	if w == int(a[1]):
		w = 1
		ans = ans + 1
print(ans)


(n, m) = map(int, input().split())
c = n
while 1:
	if n < m:
		break
	p = n % m
	n = n // m
	c += n
	n += p
print(c)


(a, b) = map(int, input().split())
c = a
while a >= b:
	c += a // b
	a = a // b + a % b
print(c)


(a, b) = list(map(int, input().split()))
ans = a
while a >= b:
	f = a // b
	ans += f
	a = a % b + f
print(ans)


line = input().split()
a = int(line[0])
b = int(line[1])
c = 0
while True:
	if a >= b:
		c += b
		a = a - b + 1
	else:
		c += a
		break
print(c)


(a, b) = map(int, input().split())
num = a
for i in range(1000):
	if a >= b:
		num += a // b
		a = a // b + a % b
print(num)


(a, b) = input().split(' ')
a = int(a)
b = int(b)
time = a
while a > 1:
	a = a / b
	time += a
print(int(time))


(a, b) = map(int, input().split())
duration = 0
remains = 0
while a > 0:
	duration += a
	a += remains
	remains = 0
	remains += a % b
	a //= b
print(duration + remains // b)


(a, b) = [int(x) for x in input().split()]
s = a
t = a
while t // b > 0:
	s = s + t // b
	t = t // b + t % b
print(s)


(a, b) = map(int, input().split())
t = 0
e = 0
while a > 0:
	t += 1
	a -= 1
	e += 1
	if e == b:
		a += 1
		e = 0
print(t)


(a, b) = map(int, input().split())
hour = a
while a >= b:
	hour += a // b
	a = a // b + a % b
print(hour)


(a, b) = map(int, input().split())
hours = a
while a >= b:
	leftover = a % b
	a = a // b
	hours += a
	a += leftover
print(hours)


(a, b) = map(int, input().split())
c = a
while a >= b:
	fac = a // b
	rem = a % b
	a = fac + rem
	c += fac
print(c)


(n, m) = map(int, input().split())
if n == m:
	print(n + 1)
elif n < m:
	print(n)
else:
	a = n
	count = 0
	while a >= m:
		b = a % m
		if b == 0:
			a = a // m
			count = count + a
		else:
			c = a // m
			a = a // m + b
			count = count + c
	print(n + count)


(n, m) = map(int, input().split())
i = 1
while n >= m * i:
	n += 1
	i += 1
print(n)


(a, b) = map(int, input().split())
cnt = a
while a >= b:
	baqimande = a % b
	a = a // b
	cnt += a
	a += baqimande
print(cnt)


(candles, mix) = map(int, input().split())
count = candles
while candles >= mix:
	count += candles // mix
	candles = candles // mix + candles % mix
print(count)


(a, b) = map(int, input().split())
ans = 0
c = 0
while a != 0:
	ans += a
	c += a
	a = c // b
	c %= b
print(ans)


(a, b) = [int(x) for x in input().split()]
sum = a
while a >= b:
	sum += a // b
	a = a // b + a % b
sum = int(sum)
print(sum)


(candles, reforge) = map(int, input().split())

def candl(number, devider):
	result = number
	while number >= devider:
		left_behind = number % devider
		number = number // devider
		result += number
		number += left_behind
	return result
print(candl(candles, reforge))


s = input()
a = s.split()
for i in range(len(a)):
	a[i] = int(a[i])
i = a[0]
while a[1] <= a[0]:
	i += int(a[0] / a[1])
	n = a[0] % a[1]
	m = int(a[0] / a[1])
	a[0] = a[0] % a[1] + int(a[0] / a[1])
print(i)


(a, b) = map(int, input().split())
s = a // b
y = a % b
count = a + s
while True:
	if (s + y) // b == 0:
		break
	else:
		tmp = s
		s = (s + y) // b
		count += s
		y = (tmp + y) % b
print(count)


def function1(a, b):
	hour = 0
	n = 0
	while a >= 1:
		hour += 1
		a -= 1
		n += 1
		if n % b == 0:
			a += 1
			n = 0
	return hour

def main():
	(a, b) = list(map(int, input().split()))
	print(function1(a, b))
main()


(a, b) = map(int, input().split())
sum = 0
while a >= b:
	c = a // b + a % b
	sum += a // b * b
	a = c
print(sum + a)


import math
(a, b) = [int(x) for x in input().split()]
r = a
while a >= 1:
	a = a / b
	r += a
print(math.floor(r))


L = input()
L = L.split()
a = int(L[0])
b = int(L[1])
T = a
while a >= b:
	T += a // b
	a = a // b + a % b
print(T)


(candles, b) = map(int, input().split())
hours = 0
candle_ends = 0
while candles > 0:
	candle_ends += candles
	hours += candles
	(candles, candle_ends) = divmod(candle_ends, b)
print(hours)


(a, b) = map(int, input().split())
num = (a * b - 1) // (b - 1)
print(num)


(a, b) = map(int, input().split())
tmp = 0
hours = 0
while a >= 0:
	if tmp >= b:
		a += 1
		a -= 1
		hours += 1
		tmp -= b
		tmp += 1
	else:
		a -= 1
		hours += 1
		tmp += 1
print(hours - 1)


inp = [int(a) for a in input().strip().split(' ')]
candles = inp[0]
needed_candles = inp[1]
hours = 0
remaining_candles = 0
while candles > 0:
	hours += candles
	new_candles = candles // needed_candles
	remaining_candles += candles % needed_candles
	if remaining_candles >= needed_candles:
		new_candles += remaining_candles // needed_candles
		remaining_candles = remaining_candles % needed_candles
	candles = new_candles
print(hours)


(n, m) = map(int, input().split())
c = n
r = 0
for i in range(1000):
	if n != 0:
		if n // m == 0:
			r = r + n
		elif n >= m:
			r = r + n % m
		if r >= m:
			c = c + 1
			r = r - m + 1
		n = n // m
		c = c + n
	else:
		print(c)
		break


(a, b) = map(int, input().split())
count = 0
total = a
while a >= b:
	count = a // b
	total += count
	a = count + a % b
print(total)


(a, b) = map(int, input().split())
z = (a - 1) // (b - 1)
print(z + a)


s = input().split(' ')
candles = int(s[0])
b = int(s[1])
h = 0
left = 0
while candles > 0:
	h += candles
	left += candles
	candles = left // b
	left = left % b
print(h)


ab = input().split()
a = int(ab[0])
b = int(ab[1])
c = a
while a >= b:
	c += a // b
	div = a // b
	rem = a % b
	a = div + rem
print(c)


(a, b) = input().split()
a = int(a)
b = int(b)
d = a // b
c = a + d
e = 1
while d >= 1:
	a = a // b + a % b
	d = a // b
	c = c + d
print(c)


(a, b) = list(map(int, input().split()))
sum = a
while True:
	c = a // b
	a = c + a % b
	sum += c
	if a < b:
		break
print(sum)


(a, b) = map(int, input().split())
answ = a
while a >= b:
	answ += a // b
	a = a // b + a % b
print(answ)


(a, b) = map(int, input().split())
i = 1
count = 0
rez = 0
while a != 0:
	a = a - 1 + rez
	count += 1
	rez = 0
	if count % b == 0:
		rez = 1
		count = 0
	elif a == 0:
		break
	i += 1
print(i)


(a, b) = map(int, input().split())
result = a
while True:
	if a < b:
		break
	else:
		result += a // b
		a = a // b + a % b
print(result)


import math
(a, b) = map(int, input().split())
hours = a
if a >= b:
	new_candles = a
	while new_candles >= b:
		if math.floor(new_candles / b) == new_candles / b:
			new_candles = math.floor(new_candles / b)
			hours += new_candles
		else:
			x = new_candles % b
			new_candles = math.floor(new_candles / b)
			hours += new_candles
			new_candles += x
	print(hours)
else:
	print(hours)


(a, b) = map(int, input().split())
print(a + ~-a // ~-b)


l = input().split(' ')
(a, b, mori, hour) = (int(l[0]), int(l[1]), 0, 0)
while a > 0 or mori >= b:
	if mori >= b:
		mori -= b
		a += 1
	a -= 1
	hour += 1
	mori += 1
print(hour)


(a, b) = [int(i) for i in input().split()]
count = 0
count += a
x = a // b
while x != 0:
	count += x
	a = x + a % b
	x = a // b
print(count)


(a, b) = map(int, input().split())

def f(a, b):
	x = a
	while a >= b:
		x = x + a // b
		a = a // b + a % b
	return x
print(f(a, b))


(a, b) = map(int, input().split())
time = a
while a // b != 0:
	time += a // b
	a -= (b - 1) * (a // b)
print(time)


(n, m) = map(int, input().split())
k = 0
for i in range(2000):
	if n > 0:
		k += 1
		n -= 1
		if i % m == 0:
			n += 1
else:
	print(k - 1)


(a, b) = map(int, input().split())
(r, l) = (0, 0)
while a:
	r += a
	l += a
	a = l // b
	l %= b
print(r)


(a, b) = list(map(int, input().split()))
result = 0
while a >= b:
	result += b
	a -= b
	a += 1
print(result + a)


(a, b) = map(int, input().split())
ans = a
r = a
while r // b >= 1:
	ans = ans + r // b
	r = r // b + r % b
print(ans)


(n, b) = map(int, input().split())
if b == 1:
	print('You Enter A Bad Number Computer Will Compute For True!!')
if b == 0:
	print('You Enter A Bad Number Computer Will Have Errors!!')
p = n
e = 0
n2 = 0
while n // b > 0:
	while n >= b:
		p = p + n // b
		n2 = n // b
		e = e + n % b
		n = n2
	e = e + n % b
	n = e
	e = 0
print(p)


(n, m) = list(map(int, input().split()))
k = 0
while n != 0:
	k += 1
	n -= 1
	if k % m == 0 and k >= m:
		n += 1
print(k)


(a, b) = map(int, input().split())
it = a
r = 0
while a >= b:
	r = a % b
	a = a // b
	it += a
	a += r
print(it)


(a, b) = map(int, input().split())
s = a
while a >= b:
	d = a // b
	s += d
	r = a % b
	a = d + r
print(s)


a = list(map(int, input().strip().split()))
t = a[0]
w = a[1]
ans = t
while t >= w:
	ans += t // w
	t = t // w + t % w
print(ans)


vals = list(input().split(' '))
a = int(vals[0])
b = int(vals[1])
h = 0
uA = 0
while a:
	h += 1
	uA += 1
	a -= 1
	if uA == b:
		a += 1
		uA = 0
print(h)


q = input().split(' ')
a = int(q[0])
b = int(q[1])
c = a
o = a
while o >= b:
	c += o // b
	o = o % b + o // b
print(c)


(a, b) = [int(x) for x in input().split()]
print((a * b - 1) // (b - 1))


(a, b) = tuple(map(int, input().split()))
s = a
x = a // b
while a // b != 0:
	s = s + x
	a = a // b + a % b
	x = a // b
print(s)


(a, b) = map(int, input().split())
ans = 0
for i in range(1, a + 1):
	ans += 1
	if ans % b == 0:
		ans += 1
print(ans)


(a, b) = map(int, input().split())
t = a
while a >= b:
	t += a // b
	a = a // b + a - a // b * b
print(int(t))


a = list(map(int, input().strip().split()))
m = a[0]
n = a[1]
c = 0
while m >= n:
	c += m // n
	m = m // n + m % n
print(c + a[0])


t = 0
k = 0
(n, b) = map(int, input().split())
while n > 0:
	t += n
	n = n + k
	k = n % b
	n = n // b
print(t)


(a, b) = [int(x) for x in input().split()]
t = 0
candle = 0
while a > 0:
	t += 1
	a -= 1
	candle += 1
	if candle % b == 0:
		c = int(candle / b)
		a += c
		candle -= c * b
print(t)


def f(a, b):
	d = 0
	while a != 0:
		if a >= b:
			k = int(a // b)
			d += k * b
			a = a + k - b * k
		else:
			d += a
			a = 0
	return d
(a, b) = list((int(x) for x in input().split()))
print(f(a, b))


(a, b) = [int(i) for i in input().split()]
print(a + int((a - 1) / (b - 1)))


def new_year_candles(c, d):
	x = c
	while c >= d:
		x += c // d
		c = c // d + c % d
	return x
f = lambda : map(int, input().split())
(a, b) = f()
print(new_year_candles(a, b))


s = input().split(' ')
(a, b) = (int(s[0]), int(s[1]))
time = 0
while a >= b:
	time += b
	a = a - b + 1
time += a
print(time)


from math import ceil, sqrt, gcd, log, floor
from collections import deque

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def li():
	return list(mi())

def main():
	(a, b) = mi()
	ans = a
	c1 = 1
	while 1:
		c = 0
		for i in range(c1, a + 1):
			if i % b == 0:
				c += 1
		if c == 0:
			break
		c1 = a + 1
		a += c
	print(a)
main()


(n, m) = [int(__) for __ in input().strip().split()]
if m == n:
	print(n + 1)
elif m > n:
	print(n)
else:
	ans = n
	su = ans // m
	re = ans % m
	while su != 0:
		re = ans % m
		ans += su
		su = (su + re) // m
	print(ans)


(a, b) = map(int, input().split())
hours = a
cur_a = a
cur_b = 0
while cur_a > 0:
	cur_b += cur_a
	cur_a = cur_b // b
	cur_b %= b
	hours += cur_a
print(hours)


(a, b) = map(int, input().strip().split())
result = a
remain = 0
while a >= b:
	remain = a % b
	result += a // b
	a = a // b + remain
print(result)


(candle, b) = map(int, input().split())
i = 0
h = 0
while candle > 0:
	candle -= 1
	i += 1
	h += 1
	if i == b:
		candle += 1
		i = 0
print(h)


(a, b) = list(map(int, input().split()))
hours = 0
r = a
while r > 0:
	hours += r
	r = int(a / b)
	a = a % b + r
print(hours)


(n, m) = map(int, input().split(' '))
res = n
while n >= m:
	res += n // m
	r = n % m
	n = n // m + r
print(res)


a = [int(i) for i in input().split()]
s = 0
g = 0
while a[0] != 0:
	a[0] = a[0] - 1
	s += 1
	g += 1
	if s == a[1]:
		a[0] += 1
		s = 0
print(g)


from sys import stdin, stdout
(a, b) = stdin.readline().split()
(a, b) = [int(a), int(b)]
print(a + (a - 1) // (b - 1))


(n, m) = [int(x) for x in input().split()]
count = n + (n - 1) // (m - 1)
print(count)


(c, b) = [int(i) for i in input().split()]
print((c * b - 1) // (b - 1))


(n, m) = [int(x) for x in input().split()]
a = n
while int(n / m) >= 1:
	a += int(n / m)
	n = int(n / m) + n % m
print(a)


(a, b) = map(int, input().split())
ans = a
bank = 0
while a // b != 0:
	bank = a % b
	a -= bank
	ans += a // b
	a = a // b
	a += bank
print(ans)


(n, m) = list(map(int, input().split()))
j = m
while j <= n:
	n += 1
	j += m
print(n)


(a, b) = [int(x) for x in input().split()]
hours = 0
while a >= b:
	hours = hours + a // b * b
	a = a // b + a % b
else:
	hours = hours + a
print(hours)


(a, b) = map(int, input().split())
count = 0
while a > 0:
	if a >= b:
		count += a // b * b
		a = a // b + a % b
	else:
		count += a
		a = 0
print(count)


l = input().split()
a = int(l[0])
b = int(l[1])
s = a
while a / b >= 1:
	s += int(a / b)
	a = int(a / b) + a % b
print(s)


(a, b) = [int(x) for x in input().split()]
ans = a
while a >= b:
	n = a // b
	ans += n
	a = n + a % b
print(ans)


(s, r) = list(map(int, input().split()))
candles = s
while 1:
	count = s // r
	s = count + s % r
	candles += count
	if s < r:
		break
print(candles)


(a, b) = map(int, input().split())
res = a
rem = 0
while a > 0:
	a += rem
	s = a // b
	res += s
	rem = a % b
	a = s
print(res)


(n, m) = map(int, input().split())
ans = n
a = n // m
ans += a
rem = n % m + a
while rem >= m:
	a1 = rem // m
	ans += a1
	rem = rem % m + a1
print(ans)


(a, b) = map(int, input().split())
burnt = 0
hours = a
while a >= b:
	hours += a // b
	a = a // b + a % b
print(hours)


from collections import Counter
(n, k) = list(map(lambda x: int(x), input().split()))
cnt = n
while n > 0:
	temp_ = int(n / k)
	n = temp_ + n % k
	cnt += temp_
	if n < k:
		break
print(cnt)


(n, k) = map(int, input().split())
res = n
while n >= k:
	res += n // k
	n = n // k + n % k
print(res)


(a, b) = [int(x) for x in input().split()]
d = 0
out = 0
while a > 0:
	a -= 1
	d += 1
	out += 1
	if out % b == 0:
		a += 1
if a == 0:
	print(d)


(a, b) = [int(x) for x in input().split()]
used = 0
counter = 0
while a > 0 or used >= b:
	counter += 1
	a -= 1
	used += 1
	if used > b:
		used -= b
		a += 1
print(counter)


(a, b) = input().split()
(a, b) = [int(a), int(b)]
print((a * b - 1) // (b - 1))


s = input().split()
a = int(s[0])
b = int(s[1])
c = 0
while a > 0:
	c += 1
	a -= 1
	if c % b == 0:
		a += 1
print(c)


(m, n) = map(int, input().split())
b = 1 + m
a = 0
while m // n >= 1:
	a += m // n
	m = m // n + (m - m // n * n)
print(a + b - 1)


I = lambda : map(int, input().split())
(n, m) = I()
a = n
while n >= m:
	z = n % m
	n = int(n / m)
	a += n
	n += z
print(a)


list = [int(x) for x in input().split()]
a = list[0]
b = list[1]
hours = 0
burn = 0
if a < b:
	print(a)
else:
	while a:
		hours += 1
		a -= 1
		burn += 1
		if burn == b:
			burn = 0
			a += 1
	print(hours)


(a, b) = map(int, input().split())
n1 = (a * b - 1) / (b - 1)
n1 = int(n1)
print(n1)


import math
inputNums = input()
a = int(inputNums.split(' ')[0])
b = int(inputNums.split(' ')[1])
burnedCandles = count = 0
for i in range(a):
	count += 1
	burnedCandles += 1
	if burnedCandles == b:
		count += 1
		burnedCandles = 1
print(count)


(full, n) = map(int, input().split())
(half, ans) = (0, 0)
ans += full
half += full
while half // n > 0:
	full = half // n
	half = half % n
	ans += full
	half += full
print(ans)


(candle, new_candle) = map(int, input().split())
burnt_candles = 0
hours = 0
while candle > 0:
	burnt_candles += 1
	candle -= 1
	if burnt_candles == new_candle:
		burnt_candles = 0
		candle += 1
	hours += 1
print(hours)


def cf_379a():
	(a, b) = map(int, input().split())
	sum_ = a
	while a >= b:
		sum_ += a // b
		a = a - a // b * b + a // b
	print(int(sum_))
cf_379a()


(a, b) = map(int, input().split())
res = a
ost = 0
while True:
	res += a // b
	a = a // b + a % b
	if a < b:
		break
print(res)


(a, b) = list(map(int, input().split()))
l = []
c = a
while a >= b:
	q = a // b
	c += q
	r = a % b
	a = q + r
print(c)


inp = str(input())
inp1 = inp.split()
a = int(inp1[0])
b = int(inp1[1])
count = 0
i = a
r = 0
while i > 0:
	count += i
	e = i // b
	r += i % b
	if r // b > 0:
		e += r // b
		r %= b
	i = e
print(count)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as c
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def outln(var):
	sys.stdout.write(str(var) + '\n')

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
(a, b) = sp()
answer = a
while a > 1:
	answer += a // b
	a = a // b + (0, a % b)[a // b > 0]
out(answer)


(n, k) = map(int, input().split())
hours = 0
while n != 0:
	n -= 1
	hours += 1
	if hours % k == 0:
		n += 1
print(hours)


(a, b) = [int(i) for i in input().split()]
hours = a
while a // b >= 1:
	hours += a // b
	a = a // b + a % b
print(hours)


(a, b) = list(map(int, input().split()))
hour = a
while a // b > 0:
	hour += a // b
	a = a // b + a % b
print(hour)


(a, b) = map(int, input().split())

def time(a, b, c=0):
	if a + c < b:
		return a
	elif a == b:
		return a + 1
	else:
		return a + time((a + c) // b, b, (a + c) % b)
print(time(a, b))


row = str(input()).split(' ')
n = int(row[0])
r = int(row[1])
aux = 0
usadas = n
recicladas = n / r
while recicladas > 1:
	usadas += int(recicladas)
	aux = float(str(recicladas - int(recicladas))[1:])
	recicladas = int(recicladas) / r
	recicladas += aux
if recicladas == 1.0:
	usadas += 1
print(usadas)


(a, b) = map(int, input().split())
count = a
piece = a
while piece // b >= 1:
	count += piece // b
	piece = piece // b + piece - piece // b * b
print(count)


(n, m) = [int(x) for x in input().split()]
d = n
k = n
l = n
while k >= 1:
	k = n / m
	n /= m
	l += k
print(int(l))


(i, n) = map(int, input().split())
candlesLit = 0
while i > 0:
	i -= 1
	candlesLit += 1
	if candlesLit % n == 0:
		i += 1
print(candlesLit)


def main():
	(a, b) = map(int, input().split())
	res = a
	while True:
		newC = a // b
		if newC == 0:
			print(res)
			return
		res += newC
		a -= newC * b
		a += newC
main()


(a, b) = [int(i) for i in input().split()]
hours = a
sub = a
remain = 0
while (sub + remain) // b > 0:
	curr = sub
	sub = (sub + remain) // b
	remain = (curr + remain) % b
	hours += sub
print(hours)


(X, Y) = input().split()
x = int(X)
y = int(Y)
candles = x
while x >= y:
	new = x // y
	reserve = x - new * y
	x = new + reserve
	candles = candles + new
print(candles)


(N, k) = map(int, input().split())
hours = N
while N >= k:
	x = N % k
	N = N // k
	hours += N
	N += x
print(hours)


__author__ = 'widoc'
(a, b) = map(int, input().split())
res = 0
rest = 0
while a > 0:
	res += a
	if a >= b:
		rest += a % b
		a = a // b
	elif a + rest >= b:
		old_a = a
		a = (a + rest) // b
		rest = (old_a + rest) % b
	else:
		break
print(res)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	(n, m) = LI()
	t = 0
	r = 0
	while 1:
		if n == 0:
			return r
		r += n
		t += n
		n = t // m
		t %= m
	return -1
print(main())


(a, b) = list(map(int, input().split()))
tot = a
rem = a
while rem >= b:
	a = rem // b
	rem -= a * b
	tot += a
	rem += a
print(tot)


(new, b) = list(map(int, input().split(' ')))
old = 0
ans = 0
while new != 0:
	ans = ans + new
	old = old + new
	new = int(old / b)
	old = old - new * b
print(ans)


(n, k) = map(int, input().split())
answ = n
while n >= k:
	tmp = n // k
	tmp2 = n % k
	answ += tmp
	n = tmp + tmp2
print(answ)


(a, b) = map(int, input().split(' '))
(ans, rem) = (0, 0)
while a > 0:
	ans += a
	a += rem
	rem = a % b
	a //= b
print(ans)


(n, m) = map(int, input().split())
x = 0
if m <= n:
	x = n + (n - m) / (m - 1) + 1
	print(int(x))
else:
	x = n
	print(x)


d = [int(x) for x in input().split(' ')]
h = 0
while d[0] > 0:
	h += 1
	d[0] -= 1
	if h % d[1] == 0:
		d[0] += 1
print(h)


(c, wc) = map(int, input().split())
k = c
w = c
while w >= wc:
	k = k + w // wc
	w = w // wc + w % wc
print(k)


def fun(a, b):
	periods = a // (b - 1)
	days = periods * b
	candles = periods * (b - 1)
	if a % (b - 1) == 0:
		return days - 1
	else:
		return days + (a - candles)
(a, b) = map(lambda x: int(x), input().split(' '))
print(fun(a, b))


(a, b) = map(int, input().split())
i = 1
while b * i <= a:
	a += 1
	i += 1
print(a)


l = [int(i) for i in input().split()]
a = l[0]
b = l[1]
c = a // b
r = a % b
e = c

def candles(a, b, c, r, e):
	while c >= 1:
		r += c % b
		c //= b
		e += c
	if r < b:
		return e
	elif r == b:
		return e + 1
	else:
		return e + candles(a, b, r // b, r % b, r // b)
if a >= b:
	d = candles(a, b, c, r, e)
	print(a + d)
else:
	print(a)


(a, b) = [int(x) for x in input().split()]
s = a
while not a < b:
	s += a // b
	a = a // b + a % b
print(s)


l = [int(x) for x in input().split()]
a = l[0]
b = l[1]
n = (a - b) // (b - 1) + 1
hour = a + n
print(hour)


(a, b) = map(int, input().split())
(c, s) = (a, 0)
while a >= b:
	s += a // b
	a = a // b + a % b
print(s + c)


(a, b) = [int(s) for s in input().split()]
(p, t) = (0, 0)
while a > 0:
	a -= 1
	p += 1
	t += 1
	if p % b == 0:
		a += 1
		p = 0
print(t)


(a, b) = list(map(int, input().split()))
s = 0
x = 0
while a != 0:
	while a > 0:
		x += a % b
		s += a
		a = a // b
	a = x // b
	x = x % b
print(s)


txt = input()
(a, b) = txt.split(' ')
a = int(a)
b = int(b)
total = a
left = 0
while True:
	add = 0
	left += a % b
	if left >= b:
		add = 1
		left = left % b
	if a < b and add != 1:
		break
	a = a // b
	a += add
	total += a
print(total)


line = input()
params = line.split(' ')
a = int(params[0])
b = int(params[1])
total_hours = a
candles = a
while candles >= b:
	total_hours += int(candles / b)
	candles = int(candles / b + candles % b)
print(total_hours)


(a, b) = [int(x) for x in input().split()]
left = a
ans = a
while left >= b:
	ans += left // b
	temp = left // b
	left = temp + left % b
print(ans)


import sys
in_str = sys.stdin.readline().split()
a = int(in_str[0])
b = int(in_str[1])
hours = a
while a >= b:
	ost = int(a % b)
	a = int(a / b)
	hours += int(a)
	a += ost
print(hours)


(a, b) = map(int, input().split())
(s, f) = (0, 0)
while True:
	if a > 0:
		s += 1
		f += 1
		a -= 1
		if f == b:
			a += 1
			f = 0
	else:
		print(s)
		break


(a, b) = [int(i) for i in input().split()]
hours = 0
if a < b:
	hours += a
else:
	while True:
		try:
			hours += b
			a = a - b + 1
			if a < b:
				hours += a
				break
		except EOFError:
			break
print(hours)


(answ, b) = map(int, input().split())
p = answ
while p // b > 0:
	answ += p // b
	p = p // b + p % b
print(answ)


(a, b) = map(int, input().split())
res = (a * b - 1) // (b - 1)
print(res)


s = input()
s = s.split()
a = int(s[0])
b = int(s[1])
rem = a
ans = a
while rem > 0:
	if rem < b:
		break
	ans += rem // b
	rem = rem // b + rem % b
print(ans)


n = [int(x) for x in input().split()]
count = n[0]
while n[0] >= n[1]:
	count = count + int(n[0] / n[1])
	n[0] = n[0] % n[1] + int(n[0] / n[1])
print(count)


(a, b) = map(int, input().split())
k = 0
while a != 0:
	a -= 1
	k += 1
	if k % b == 0:
		a += 1
print(k)


(a, b) = [int(i) for i in input().split()]
t = 0
burnt = 0
while a:
	a -= 1
	t += 1
	burnt += 1
	if burnt == b:
		burnt = 0
		a += 1
print(t)


(a, b) = map(int, input().split())
i = 1
x = 0
curra = a
currb = 0
while curra != 0:
	x += curra
	currb += curra
	curra = currb // b
	currb = currb % b
print(x)


(n, m) = map(int, input().strip().split(' '))
k = 0
day = 0
while n != 0:
	n -= 1
	k += 1
	if k == m:
		n += 1
		k = 0
	day += 1
print(day)


(a, b) = map(int, input().split())
ans = a
burnt = 0
hours = 0
while ans > 0 or burnt >= b:
	ans = ans - 1
	burnt = burnt + 1
	if burnt > b:
		burnt = burnt - b
		ans = ans + 1
	hours = hours + 1
print(hours)


import math
(a, b) = [int(x) for x in input().split()]
total = a
while a >= b:
	total += math.floor(a / b)
	a = math.floor(a / b) + a % b
print(total)


(a, b) = map(int, input().split())
result = a
while a >= b:
	result += a // b
	a = a // b + a % b
print(result)


from sys import stdin
(a, b) = [int(c) for c in stdin.readline().split()]
burnt = 0
burnt_candle = 0
time = 0

def re(candle, burnt_candle):
	global time
	time = time + candle
	burnt_candle = burnt_candle + candle
	candle = burnt_candle // b
	burnt_candle = burnt_candle - candle * b
	if candle > 0:
		return re(candle, burnt_candle)
	else:
		return time
print(re(a, 0))


(a, b) = map(int, input().split())
time = a
c = a
d = 0
while c >= b:
	d = c % b
	c = c // b
	time = time + c
	c = c + d
print(time)


(a, b) = tuple(map(int, input().split()))
res = a
while True:
	t = int(a / b)
	r = a % b
	res += t
	a = t + r
	if a < b:
		break
print(res)


(a, b) = map(int, input().split())
total = a
count = 0
while True:
	if b <= a and a >= b:
		total += a // b
		a = a // b + a % b
	else:
		break
print(total)


from sys import stdin, stdout
(a, b) = map(int, stdin.readline().split())
h = a
s = 0
while a >= b:
	h += a // b
	s = a % b
	a = a // b + s
print(h)


(n, k) = map(int, input().split())
a = n
while n >= k:
	a += n // k
	n = n // k + n % k
print(a)


(a, b) = map(int, input().split())
hr = a
while a >= b:
	d = a // b
	hr = hr + d
	r = a % b
	a = d + r
print(hr)


(a, b) = input().split()
a = int(a)
b = int(b)
count = a
while a // b > 0:
	count += a // b
	a = a // b + (a - a // b * b)
print(count)


(a, b) = [int(x) for x in input().split()]
total = 0
(cura, curb) = (a, 0)
while cura >= b:
	shift = cura % b
	(cura, curb) = (cura - shift, curb + shift)
	total += cura
	cura = cura // b
	if cura < b:
		cura += curb
		curb = 0
total += cura
print(total)


def doit(number, recycle_number):
	if number < recycle_number:
		return number
	temp = 0
	temp = number - number % recycle_number
	number = temp // recycle_number + number % recycle_number
	return temp + doit(number, recycle_number)
numbers = list(map(int, input().split()))
print(doit(numbers[0], numbers[1]))


(candles, dying) = list(map(int, input().split()))
print((candles * dying - 1) // (dying - 1))


(a, b) = list(map(int, input().split()))
k = 0
s = a
q = 0
while s > 0:
	k += s
	q += s
	s = q // b
	q = q - s * b
print(k)


(a, b) = map(int, input().split())
(cur, dead) = (a, 0)
h = a
while cur > 0:
	dead += cur
	cur = dead // b
	dead = dead % b
	h += cur
print(h)


def candles(a, b):
	burnt_candles = a
	while a >= b:
		(q, r) = divmod(a, b)
		burnt_candles += q
		a = q + r
	return burnt_candles
(a, b) = map(int, input().split())
print(candles(a, b))


s = [int(x) for x in input().split()]
a = s[0]
b = s[1]
t = 0
for i in range(10000000):
	if a >= b:
		m = int(a / b)
		c = a - m * b
		t += m * b
		a = m + c
	elif a >= 0 and a < b:
		t += a
		break
print(t)


a = [int(x) for x in input().split()]
n = a[0]
b = a[1]
t = n
while n >= b:
	n = n - b + 1
	t = t + 1
print(t)


(a, b) = map(int, input().split())
flag = True
count = a
while flag != False:
	if a >= b:
		count = count + a // b
		a = a // b + a % b
	else:
		flag = False
print(count)


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
(a, b) = map(int, input().split())
ans = 0
c = 0
while a > 0:
	ans += a
	(a, c) = ((a + c) // b, (a + c) % b)
print(ans)


(a, b) = map(int, input().split())
ans = a
rest = 0
while a:
	t = a + rest
	a = t // b
	rest = t % b
	ans += a
print(ans)


(a, b) = map(int, input().strip().split(' '))
res = 0
while a >= b:
	res += a - a % b
	a = a // b + a % b
res += a
print(res)


(a, b) = map(int, input().split())
count = 0
i = 1
while i * b <= a:
	i += 1
	a += 1
while a > 0:
	count += 1
	a -= 1
print(count)


(a, b) = [int(i) for i in input().split()]
h = 0
_ = 0
while a:
	h += 1
	a -= 1
	_ += 1
	if _ == b:
		_ = 0
		a += 1
print(h)


(a, b) = input().split()
a = int(a)
b = int(b)
m = 1
co = 0
co = co + a
while m:
	if a < b:
		m = 0
	co = co + a // b
	x = a % b
	a = a // b
	a = a + x
print(co)


(a, b) = [int(i) for i in input().strip().split()]
total = 0
rest = 0
while True:
	if a == 0:
		print(total)
		break
	total += a
	tmp = (a + rest) % b
	a = (a + rest) // b
	rest = tmp


(a, b) = map(int, input().strip().split(' '))
time = a
while True:
	rem = a % b
	a = int(a / b)
	time += a
	a = a + rem
	if int(a / b) == 0:
		break
	else:
		continue
print(int(time))


[a, b] = map(int, input().split())
ans = a
res = 0
while a >= b:
	res = a % b
	ans += (a - res) / b
	a = (a - res) / b + res
print(int(ans))


(n, m) = map(int, input().split())
h = n
while n >= m:
	d = n // m
	h += d
	x = n % m
	n = d + x
print(h)


import math

def main():
	(a, b) = (int(i) for i in input().split(' '))
	l = a
	r = a
	while r >= b:
		a = r // b
		r += a - a * b
		l += a
	print(l)
	pass
main()


l = [int(i) for i in input().split()]
x = l[0]
b = l[1]
m = 0
w = 0
while x != 0:
	m = x + m
	w = w + x
	x = w // b
	w = w % b
print(m)


import math
(a, b) = map(int, input().split())
count = a
left = 0
while a > 0:
	a += left
	count += math.floor(a / b)
	left = a % b
	a = math.floor(a / b)
	check = math.floor((a + left) / b)
	if check < 0:
		a = 0
print(int(count))


import math
(a, b) = map(int, input().split())
count = a
ost = 0
while True:
	ost = a - b * math.floor(a / b) + ost
	a = math.floor(a / b)
	count += a
	if a == 0:
		if ost < b:
			break
		else:
			a = ost
			ost = 0
print(count)


ab = input().split()
a = int(ab[0])
b = int(ab[1])
result = a
debris = a
while debris >= b:
	result += int(debris / b)
	debris = int(debris / b) + debris % b
print(result)


(n, k) = map(int, input().split())
ans = n
while n >= k:
	ans += int(n / k)
	n = int(n / k) + int(n % k)
print(int(ans))


def main():
	(candles, b) = map(int, input().split(' '))
	hours = 0
	l = 0
	while candles > 0:
		hours += candles
		l += candles % b
		candles //= b
		if l >= b:
			x = l // b
			l %= b
			candles += x
	return hours
print(main())


k = input().split()
a = int(k[0])
b = int(k[1])
noc = 0
k = 0
while a > 0:
	noc += a
	k += a % b
	a = a // b
while k > 0:
	noc += k // b
	if k > b:
		k = k % b + k // b
	else:
		k = k // b
print(noc)


(n, k) = [int(i) for i in input().split()]
nd = 0
r = 0
while n > 0:
	nd = nd + n
	m = (n + r) // k
	r = n + r - k * m
	n = m
print(nd)


def candles(a, b):
	ans = 0
	while a >= b:
		ans += b
		a -= b
		a += 1
	return ans + a
(a, b) = list(map(int, input().rstrip().split()))
print(candles(a, b))


(a, b) = map(int, input().split())
count = a
burn = a
while burn >= b:
	count += burn // b
	rem = burn % b
	burn = burn // b + rem
print(count)


def candle(a, b):
	return a // b + candle(a // b + a % b, b) if a >= b else 0
(a, b) = map(int, input().split())
print(a + candle(a, b))


line = input()
(a, b) = line.split(' ')
a = int(a)
b = int(b)
s = a
while int(s / b) > 0:
	a += int(s / b)
	y = s % b
	s = int(s / b) + y
print(a)


(n, m) = map(int, input().split())
x = n

def loop(n, m):
	global x
	while n >= m:
		if n % m == 0:
			x += n // m
			return loop(n // m, m)
		else:
			y = n // m + n % m
			x += n // m
			return loop(y, m)
loop(n, m)
print(x)


import math
s = input().split()
a = float(s[0])
b = float(s[1])
h = 0
while a >= 1:
	h += math.floor(a)
	a = math.floor(a) / b + a % 1
print(h)


numbers = [int(i) for i in input().split()]
a = numbers[0]
b = numbers[1]
remain = 0
candles = a
worn = 0
total = 0
while True:
	hours = candles
	total += hours
	if hours == 0:
		break
	worn = candles + remain
	candles = 0
	hours = 0
	candles = worn // b
	remain = worn % b
print(total)


(a, b) = [int(i) for i in input().split()]
naswer = 0
c = 0
while a > 0:
	naswer = naswer + a
	c = c + a
	a = c // b
	c = c % b
print(naswer)


(a, b) = map(int, input().split())
h = a
while a // b > 0:
	h += a // b
	a -= a // b * (b - 1)
print(h)


(n, m) = map(int, input().split())
ans = n
while int(n):
	ans += n / m
	n = n / m
print(int(ans))


(n, t) = map(int, input().split())
tt = 0
while n >= t:
	n = n - t + 1
	tt += 1
print(tt * t + n)


(a, b) = [int(x) for x in input().split()]
n = 0
bu = 0
while a:
	n += a
	bu += a % b
	a = a // b
	if not a and bu >= b:
		a = bu // b
		bu = bu % b
print(n)


def main():
	(a, b) = list(map(int, input().split()))
	light_out = 0
	total_time = 0
	while a > 0:
		total_time += 1
		a -= 1
		light_out += 1
		if light_out == b:
			light_out = 0
			a += 1
	print(total_time)
main()


(a, b) = [int(x) for x in input().split()]
cnt = a
new = 1
if a % b == 0:
	while new > 0:
		new = a // b
		cnt += a // b
		a = a // b + a % b
	print(cnt)
else:
	while new > 0:
		new = a // b
		cnt += a // b
		rem = a % b
		a = a // b + rem
	print(cnt)


(a, b) = map(int, input().split())
h = a
x = a // b
while x > 0:
	x = a // b
	h += x
	a = a % b + x
print(h)


def f(a, b):
	return (a - 1) // (b - 1) + a
(a, b) = map(int, input().split())
print(f(a, b))


l = list(map(int, input().split()))
total = 0
reminder = 0
while l[0] != 0:
	total += l[0]
	reminder += l[0] % l[1]
	l[0] = l[0] // l[1]
while reminder // l[1] != 0:
	total += reminder // l[1]
	reminder = reminder % l[1] + reminder // l[1]
print(total)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
h = 0
(a, b) = invr()
while True:
	if a >= b:
		a -= b - 1
		h += b
	else:
		h += a
		break
print(h)


(a, b) = input().split()
(a, b) = (int(a), int(b))
hours = a
while a >= b:
	hours = hours + a // b
	a = a // b + a % b
print(hours)


thing = input()
thing = thing.split(' ')
a = int(thing[0])
b = int(thing[1])
time = 0
newCandles = a
oldCandles = 0
while oldCandles >= b or newCandles > 0:
	time += newCandles
	oldCandles += newCandles
	newCandles = int(oldCandles / b)
	oldCandles -= b * int(oldCandles / b)
print(time)


import math
import itertools
gh = lambda : map(int, input().split())
mod = 998244353
mod = int(mod)

def main():
	(x, y) = gh()
	cnt = 0
	while x > 0:
		x -= 1
		cnt += 1
		if cnt % y == 0:
			x += 1
	print(cnt)
main()


(a, b) = map(int, input().split())
hours = a
while True:
	c = a // b
	a = c + a % b
	hours += c
	if a < b:
		break
print(hours)


(a, b) = [int(i) for i in input().split()]
res = 0
k = 0
while a > 0:
	res += a
	(a, k) = ((a + k) // b, (a + k) % b)
print(res)


candles = input().split()
new_candles = int(candles[0])
burnt_candles = int(candles[1])
hours = new_candles
while new_candles >= burnt_candles:
	hours += new_candles // burnt_candles
	new_candles = new_candles % burnt_candles + new_candles // burnt_candles
print(int(hours))


(a, b) = map(int, input().split(' '))
hours = 0
hours = hours + a
divide = a / b
while True:
	hours = hours + divide
	if divide / b <= 1:
		divide = divide / b
		hours = hours + divide
		print(int(hours))
		break
	else:
		divide = divide / b
		continue


l = input()
(a, b) = l.split()
(a, b) = (int(a), int(b))
hours = a
while a >= b:
	c = a % b
	a = a // b
	hours += a
	a += c
print(hours)


inp = input()
lt = inp.split(' ')
nums = list(map(int, lt))
a = nums[0]
b = nums[1]
h = a
while a >= b:
	g = a // b
	r = a % b
	h = h + g
	a = g + r
print(h)


import sys

class Candles:

	def __init__(self, original, renew):
		self.light = original
		while original >= renew:
			original -= renew
			self.light += 1
			original += 1

	def getLight(self):
		return self.light

def main():
	(a, b) = [int(x) for x in sys.stdin.readline().strip().split()]
	vasily = Candles(a, b)
	print(vasily.getLight())
main()


import math
(a, b) = map(int, input().split())
t = 0
c = 0
while c >= b or a:
	t += a
	c += a
	a = math.floor(c / b)
	c = c % b
print(t)


from sys import stdin, stdout
from collections import *
st = lambda : list(stdin.readline().strip())
li = lambda : list(map(int, stdin.readline().split()))
mp = lambda : map(int, stdin.readline().split())
inp = lambda : int(stdin.readline())
pr = lambda n: stdout.write(str(n) + '\n')
mod = 1000000007
INF = float('inf')

def solve():
	(a, b) = mp()
	ans = a
	while a >= b:
		a -= b
		ans += 1
		a += 1
	pr(ans)
for _ in range(1):
	solve()


x = list(map(int, input().split()))
n = 0
while x[0] != n:
	n += 1
	if n % x[1] == 0:
		x[0] = x[0] + 1
print(n)


(n, m) = map(int, input().split(' '))
su = n
while n != 0:
	su += n // m
	d = 0
	if n >= m:
		d = n % m
	n = n // m + d
print(su)


(a, b) = map(int, input().split())
c = a
k = 1
while k != 0:
	k = a // b
	q = a - b * k
	a = k + q
	c = c + k
	if k == 0:
		break
print(c)


s = input().split(' ')
a = int(s[0])
b = int(s[1])
r = 0
s = 0
while a > 0:
	s = s + a
	new = (a + r) // b
	r = (a + r) % b
	a = new
print(s)


(a, b) = map(int, input().split())
output = a
candles = a // b
overflow = a % b
while candles >= 1 or overflow >= b:
	if overflow >= b:
		overflow -= b
		candles += 1
	output += candles
	a = candles
	candles = a // b
	overflow += a % b
print(output)


(a, b) = map(int, input().split())
time = a
for x in range(1001):
	if a // b >= 1:
		time += a // b
		a = a // b + a % b
	if a < 1:
		break
print(time)


import math
(a, b) = [int(i) for i in input().split()]
jieguo = a
for i in range(a):
	if a / b >= 1.0:
		c = math.floor(a / b)
		a = a - c * b + c
		jieguo = jieguo + c
print(jieguo)


(a, b) = [int(x) for x in input().split()]
answer = last = a
while last >= b:
	answer += last // b
	last = last // b + last % b
print(answer)


(n, m) = map(int, input().split())
nr = n
while n // m > 0:
	notlighted = n % m
	nr += n // m
	n = n // m + notlighted
print(nr)


(a, b) = map(int, input().split())
hours = a
while a // b >= 1:
	hours += a // b
	a = a // b + a % b
print(hours)


from math import floor
x = input().split()
a = int(x[0])
b = int(x[1])
hours = 0
unused = 0.01
used = a
while used >= 1:
	hours += used
	cache = used // b
	unused = unused + used % b / b
	used = cache + floor(unused)
	unused = unused - floor(unused)
print(hours)


(a, b) = map(int, input().split())
ans = 0
dead_ones = 0
while a > 0:
	ans += a
	dead_ones += a
	a = dead_ones // b
	dead_ones %= b
print(ans)


a = [int(x) for x in input().split()]
burnt = 0
remainder = 0
x = 0
while a[0] != 0:
	x += a[0]
	burnt = remainder + a[0]
	a[0] = burnt // a[1]
	remainder = burnt % a[1]
print(x)


(n, b) = map(int, input().split())
c = 0
while n:
	n -= 1
	c += 1
	if c % b == 0:
		n += 1
print(c)


(q, w) = map(int, input().split())
count = q
while q // w:
	count += q // w
	q = q // w + q % w
print(count)


(a, b) = map(int, input().split())
temp: int = 0
s = 0
x = a
y = 0
while a >= b:
	temp = int(a / b)
	s += temp
	y = a % b
	a = temp + y
	if a == 0:
		break
print(int(x + s))
1


s = input()
s1 = s.split(' ')
a = int(s1[0])
b = int(s1[1])
day = 0
while a != 0:
	a = a - 1
	day += 1
	if day % b == 1:
		day += 1
print(day - 1)


ab = [int(x) for x in input().split()]
cura = ab[0]
curb = 0
count = 0
while cura > 0:
	count += cura
	curb += cura
	cura = curb // ab[1]
	curb = curb % ab[1]
print(count)


(a, b) = input().split()
a = int(a)
b = int(b)
r = a
j = a
while j >= b:
	p = j // b
	r += p
	q = j % b
	j = p + q
print(r)


(a, b) = map(int, input().split())
time = a
num = 0
while True and a > 0:
	num += a % b
	a = a // b
	if num >= b:
		num -= b
		a += 1
	time += a
print(time)


(a, b) = list(map(int, input().split()))
print((a * b - 1) // (b - 1))


(a, b) = map(int, input().split())
answer = a
while a >= b:
	answer += a // b
	a = a % b + a // b
print(answer)


(a, b) = map(int, input().split())
d = a
while a >= b:
	d = d + a // b
	a = a // b + a % b
print(d)


(a, b) = list(map(int, input().split()))
poc = 0
while a >= b:
	x = a // b
	zv = a % b
	x = x * b
	poc += x
	a = x // b + zv
print(poc + a)


__author__ = 'runekri3'
(a, b) = list(map(int, input().split()))
candles = a
burnt_candles = 0
total_hours = 0
while 1:
	remakeable_candles = int(burnt_candles / b)
	candles += remakeable_candles
	burnt_candles -= remakeable_candles * b
	if candles <= 0:
		break
	total_hours += candles
	burnt_candles += candles
	candles = 0
print(total_hours)


a = input()
b = a.split()
count = 0
c = int(b[0])
while int(b[1]) <= c:
	count += c - c % int(b[1])
	c = c // int(b[1]) + c % int(b[1])
else:
	count += c
print(count)


(a, b) = [int(i) for i in input().split()]
g = a
p = 0
l = 0
while True:
	l += g
	p += g
	g = int(p / b)
	p -= b * g
	if p < b and (not g):
		print(l)
		exit(0)


[a, b] = [int(x) for x in input().split()]
candle = a
leftover = 0
day = 0
while candle > 0:
	day += 1
	candle -= 1
	leftover += 1
	if leftover == b:
		candle += 1
		leftover = 0
print(day)


(n, m) = map(int, input().split())
q = n
r = 0
w = n
while w >= m:
	q += w // m
	w = w // m + (w - w // m * m)
print(q)


(n, b) = map(int, input().split())
count = n
while n >= b:
	count += n // b
	n = n // b + n % b
print(count)


import sys, os.path
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
sys.setrecursionlimit(10 ** 5)

def i():
	return sys.stdin.readline().strip()

def ii():
	return int(sys.stdin.readline())

def li():
	return list(sys.stdin.readline().strip())

def mii():
	return map(int, sys.stdin.readline().split())

def lii():
	return list(map(int, sys.stdin.readline().strip().split()))

def solve():
	(a, b) = mii()
	s = a
	while a >= b:
		s += a // b
		a = a // b + a % b
	print(s)
for _ in range(1):
	solve()


(a, b) = map(int, input().split())
x = a
while a >= b:
	x = x + a // b
	a = a // b + a % b
print(x)


(n, k) = list(map(int, input().split(' ')))
c = 0
i = 1
c = n
while i > 0:
	rem = n % k
	n = n // k
	c = c + n
	n = rem + n
	if n < k:
		break
print(c)


(a, b) = map(int, input().split())
counter = a
temp = a
while temp // b != 0:
	counter += temp // b
	temp = temp // b if temp % b == 0 else temp // b + temp % b
print(counter)


def cnt(n, b):
	ans = crumb = n
	while crumb >= b:
		ans += crumb // b
		crumb = crumb // b + crumb % b
	return ans
(a, b) = map(int, input().split())
print(cnt(a, b))


(x, y) = [int(x) for x in input().split()]
b = 0
h = 0
while x > 0:
	x -= 1
	b += 1
	if b == y:
		b = 0
		x += 1
	h += 1
print(h)


num = input()
arr = []
count = 0
for i in range(0, len(num)):
	if num[i] == ' ':
		arr.append(int(num[count:i]))
		count = i + 1
	elif i == len(num) - 1:
		arr.append(int(num[count:len(num)]))
finished = None
count = 0
using = arr[0]
dead = 0
while finished == None:
	if using == 0 and dead < arr[1]:
		break
	elif using > 0:
		using -= 1
		dead += 1
		count += 1
	else:
		using = int(dead / arr[1])
		dead = dead % arr[1]
print(count)


(a, b) = input().split()
a = int(a)
b = int(b)
t = a
while a // b >= 1:
	t += a // b
	a = a // b + a % b
print(t)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
(a, b) = map(int, input().split(' '))
r = a
n = a / b
n = int(round(n - 0, 499999999))
r += n
m = a % b + n
while m >= b:
	n = m / b
	n = int(round(n - 0, 499999999))
	r += n
	m = m % b + n
print(r)


(x, k) = map(int, input().split())
print(int(x * k / (k - 1) - 1 / 10 ** 10))


arr = [int(x) for x in input().split()]
n = arr[0]
while arr[0] >= arr[1]:
	n = n + int(arr[0] / arr[1])
	arr[0] = arr[0] % arr[1] + int(arr[0] / arr[1])
print(n)


(n, m) = map(int, input().split())
count1 = count2 = 0
while n != 0:
	n -= 1
	count1 += 1
	count2 += 1
	if count2 == m:
		n += 1
		count2 = 0
print(count1)


(a, b) = list(map(int, input().split()))
n = a
while a // b != 0:
	n += a // b
	a = a // b + a % b
print(n)


(n, m) = input().split()
(n, m) = (int(n), int(m))
ans = 0
k = 0
while n > 0:
	ans += n
	newk = (n + k) % m
	newn = (n + k) // m
	k = newk
	n = newn
print(ans)


(n, m) = map(int, input().split(' '))
days = []
for i in range(1, 3 * n):
	days.append(i)
s = 0
i = 0
while s < n:
	if days[i] % m != 0:
		s += 1
	i += 1
print(i)


n = input().split()
a = int(n[0])
b = int(n[1])
x = 0
y = 0
while 1 <= a <= 1000 and 2 <= b <= 1000:
	x = x + 1
	a = a - 1
	y = y + 1
	if y == b:
		a = a + 1
		y = 0
print(x)


(x, y) = list(map(int, input().split()))
c = 0
ans = 0
while x > 0:
	ans += x
	c += x
	x = 0
	x += c // y
	c %= y
print(ans)


nm = input().split()
nm = [int(x) for x in nm]
n = nm[0]
m = nm[1]
bivajjo = n
result = n
while True:
	if bivajjo // m + bivajjo % m >= m:
		result += bivajjo // m
		bivajjo = bivajjo // m + bivajjo % m
	else:
		result += bivajjo / m
		break
print(int(result))


(a, b) = [int(i) for i in input().split()]
count = 0
res = 0
while a > 0:
	res += 1
	a -= 1
	count += 1
	if count == b:
		a += 1
		count = 0
print(str(res))


s = input()
l = s.split(' ')
a = int(l[0])
b = int(l[1])
toBurn = 0
burnt = a
total = a
i = 0
while int(burnt / b) > 0:
	toBurn = int(burnt / b)
	burnt = burnt % b
	total += toBurn
	burnt += toBurn
	toBurnt = 0
print(total)


(a, b) = map(int, input().split())
new = a // b
left = a % b
ultimatesum = a + new
while new > 0:
	new2 = new + left
	new = new2 // b
	left = new2 % b
	ultimatesum += new
print(ultimatesum)


(a, b) = map(int, input().split())
ans = a
left = 0
while a > 0:
	while a > 0:
		ans += a // b
		left += a % b
		a = a // b
	if left < b:
		a = 0
	else:
		a = left
		left = 0
print(ans)


(a, b) = map(int, input().split(' '))
out = a
nam = 0
while a > 0:
	(a, nam) = divmod(a + nam, b)
	out += a
print(out)


(a, b) = [int(x) for x in input().split()]
hours = 0
ctr = 0
while a > 0:
	hours += 1
	a -= 1
	ctr += 1
	if ctr == b:
		ctr = 0
		a += 1
print(hours)


a = list(map(int, input().split()))
candle = a[0]
extinguished_candles = a[1]
i = 1
answer = 0
while candle > 0:
	candle -= 1
	answer += 1
	if answer == extinguished_candles * i:
		i += 1
		candle += 1
print(answer)


def solve():
	ans = a
	candles = a
	remainder = 0
	while (candles + remainder) // b > 0:
		copy = candles + remainder
		candles = (candles + remainder) // b
		remainder = copy % b
		ans += candles
	return ans
(a, b) = map(int, input().split())
print(solve())


(a, b) = map(int, input().split())

def light(wentOut, b):
	if wentOut < b:
		return 0
	newCandle = int(wentOut / b)
	left = wentOut % b
	return newCandle + light(newCandle + left, b)
print(a + light(a, b))


x = input()
(x, y) = x.split()
(x, y) = (int(x), int(y))
ans = x
while x >= y:
	ans = ans + x // y
	x = x % y + x // y
print(int(ans))


import math
from collections import defaultdict, Counter, deque
INF = float('inf')

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def isPrime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def vars():
	return map(int, input().split())

def array():
	return list(map(int, input().split()))

def main():
	(n, b) = vars()
	ans = 0
	unused = 0
	while n > 0:
		ans += n
		unused += n - n // b * b
		ans += unused // b
		unused += unused // b
		unused -= unused // b * b
		n //= b
	print(ans)
t = 1
for _ in range(t):
	main()


(a, b) = map(int, input().split())
n = a
r = 0
while a >= b - r:
	a = (a + r) / b
	n = n + int(a)
	r = (n - int(a)) % b
print(n)


import math
(a, b) = [int(x) for x in input().strip().split()]

def recur(can):
	if can < 1:
		return can
	else:
		return can + recur(can / b)
val = recur(a)
print(str(math.floor(val)))


(a, b) = map(int, input().split())
hours = 0
candles = a
hours += candles
left_overs = candles
while left_overs >= b:
	new_candles = left_overs // b
	left_overs = left_overs % b + new_candles
	hours += new_candles
print(hours)


p = input().split()
a = int(p[0])
b = int(p[1])
sum1 = a
y = 0
i = 1
while True:
	x = a // b
	y = y + a % b
	sum1 = sum1 + x
	a = x
	if a < b:
		s = y + a
		break
	i = i + 1
sum2 = 0
q = 0
i = 1
while True:
	w = s // b
	q = q + s % b
	sum2 = sum2 + w
	s = w
	if s < b:
		n = q + s
		break
	i = i + 1
print(sum1 + sum2 + n // b)


(a, b) = map(int, input().split())
total = 0
f = a
half = 0
while f > 0:
	total += f
	half += f
	f = half // b
	half %= b
print(total)


import sys
(a, b) = [int(el) for el in input().split()]
res = a
cond = True
while cond:
	(div, mod) = divmod(a, b)
	a = div + mod
	res += div
	cond = a >= b
print(res)


(a, b) = map(int, input().split())
res = a
while 1:
	res += a // b
	a = a // b + a % b
	if a < b:
		break
print(res)


import re
s = input()
d = re.findall('\\d+', s)
a = int(d[0])
b = int(d[1])
hours = a
col = a
while col % b + col // b >= b:
	hours = hours + col // b
	col = col // b + col % b
hours = hours + col // b
print(hours)


(x, y) = [int(x) for x in input().split()]
acu = x
while x >= y:
	x = x - y
	acu += 1
	x = x + 1
print(acu)


(a, b) = map(int, input().split())
count = 0
count += a
while a // b > 0:
	n = a // b
	c = a % b
	count += n
	a = n + c
print(count)


(a, b) = input().split()
a = int(a)
b = int(b)
sum = a
while a // b != 0:
	sum = sum + a // b
	a = a // b + a % b
print(sum)


(n, k) = map(int, input().split())
su = n
while True:
	c = n // k
	n = c + n % k
	su += c
	if n < k:
		break
print(su)


(a, b) = map(int, input().split())
ans = a
while a >= b:
	ans += a // b
	a = a // b + a % b
print(ans)


(a, b) = map(int, input().split())
ans = a
rem = 0
if b == 0:
	print(a)
	exit(0)
while a // b:
	rem = a % b
	ans += a // b
	a = a // b + rem
print(ans)


(a, b) = map(int, input().split())
s = a
while a >= b:
	di = a // b
	s += di
	r = a % b
	a = di + r
print(s)


def func(START, D, REM, ANS):
	if START < D and START + REM < D:
		return ANS
	elif START >= D:
		while START >= D:
			REM += START % D
			START //= D
			ANS += START
		REM += START % D
		return func(REM, D, 0, ANS)
	else:
		START += REM
		REM = 0
		while START >= D:
			REM += START % D
			START //= D
			ANS += START
		REM += START % D
		return func(REM, D, 0, ANS)
(C, D) = map(int, input().split())
REM = C % D
START = C // D
ANS = C + START
print(func(START, D, REM, ANS))


(a, b) = input().split()
a = int(a)
b = int(b)
counter = a
while a >= b:
	counter += int(a / b)
	a = a % b + int(a / b)
print(counter)


n = input()
(a, b) = n.split(' ')
a = int(a)
b = int(b)
total = a
while a >= b:
	div = a // b
	total = total + div
	mod = a % b
	a = div + mod
print(int(total))


(a, b) = map(int, input().split())
count = a
bank = 0
while a + bank >= b:
	tmp = a
	a = (a + bank) // b
	bank = (tmp + bank) % b
	count += a
print(count)


def candles(big, small, t):
	if big > 0:
		return big + candles(0, small + big, t)
	if small < t:
		return 0
	return candles(small // t, small % t, t)
(a, b) = map(int, input().split())
print(candles(a, 0, b))


(a, b) = input().split()
tunde = 0
jaak = 0
terveid = int(a)
while True:
	tunde += terveid
	poolikuid = terveid + jaak
	terveid = poolikuid // int(b)
	jaak = poolikuid % int(b)
	if terveid == 0:
		break
print(tunde)


(a, b) = map(int, input().split())
hours = a
candles = a
while candles >= b:
	hours += candles // b
	candles = candles % b + candles // b
print(hours)


(a, b) = list(map(int, input().split()))
hours = a
while a != 1:
	if a % b == 0:
		hours += a // b
		a //= b
	elif a > b and a % b != 0:
		hours += a // b
		a = a // b + a % b
	elif a < b:
		break
print(hours)


(a, b) = map(int, input().split())
sum = 0
while a > 0:
	sum += 1
	a -= 1
	if sum % b == 0:
		a += 1
print(sum)


(a, b) = map(int, input().split())

def answer(a, b):
	if a < b:
		return a
	else:
		return a - a % b + answer(int(a / b) + a % b, b)
print(int(answer(a, b)))


(a, b) = map(int, input().split())
d = lambda v: v // b and v // b + d(v // b + v % b)
print(d(a * b))


x = [int(i) for i in list(input().split(' '))]

def t(x, z, k):
	l = x + k // z
	k = l + k % z
	if k >= z:
		l += t(0, z, k)
	return l
l = t(x[0], x[1], 0)
print(l)


(a, b) = list(map(int, input().split()))
(start, stop) = (0, a)
while start < stop:
	start += b
	if start <= stop:
		stop += 1
print(stop)


bot = True
(a, b) = map(int, input().split())
print((a - 1) // (b - 1) + a)


(a, b) = map(int, input().split())
(count, current, extra) = (0, a, 0)
while current > 0:
	count += current
	current += extra
	extra = current % b
	current = current // b
print(count)


(a, b) = input().split(' ')
(a, b) = (int(a), int(b))
used = a
not_used = 0
hours = 0
while used != 0:
	hours += used
	not_used += used
	used = not_used // b
	not_used = not_used % b
print(hours)


(a, b) = map(int, input().split())
c = str(a)
n = 0
t = a
for nn in range(500):
	t = a // b
	tt = a % b
	if t == 0:
		break
	else:
		n = n + t
		a = t + tt
print(int(c) + n)


(a, b) = map(int, input().split())
if b > a:
	print(a)
else:
	s = a
	while True:
		k = a // b
		r = a % b
		s = s + k
		a = r + k
		if a < b:
			break
	print(s)


(a, b) = map(int, input().strip().split())
s = a
while a > 0:
	if a < b:
		break
	temp = a % b
	a //= b
	s += a
	a += temp
print(s)


s = input().split()
a = int(s[0])
b = int(s[1])
count = 0
while a > 0:
	a -= 1
	count += 1
	if count % b == 0:
		a += 1
print(count)


s = input().split()
(a, b) = (int(s[0]), int(s[1]))
ans = 0
went = 0
while True:
	a -= 1
	ans += 1
	went += 1
	if went >= b:
		went -= b
		a += 1
	if a == 0:
		break
print(ans)


import math
(n, b) = map(int, input().split())
full = n
ost = 0
count = 0
while full > 0:
	count += full
	ost += full
	full = 0
	if ost >= b:
		full += ost // b
		ost %= b
print(count)


import math
(a, b) = map(int, input().split())
k = a
while a >= b:
	k += a // b
	a = a // b + a % b
print(k)


a = list(map(int, input().split())) + [0, 0]
while (a[0] > 0) | (a[2] > a[1]):
	(a[0], a[2], a[3]) = (0, a[2] + a[0], a[3] + a[0])
	(a[0], a[2]) = (a[2] // a[1], a[2] % a[1])
print(a[3])


(a, b) = [int(i) for i in input().split(' ')]
hours = a
initial_candles = a
while hours // b - (hours - initial_candles) > 0:
	hours += hours // b - (hours - initial_candles)
print(hours)


import math
(n, m) = map(int, input().split())
s = n
l = n
while n > 0:
	n = math.floor(l / m)
	l = l % m + n
	s += n
print(s)


(n, k) = map(int, input().split())
c = 0
c += n
while n >= k:
	c += n // k
	n = n % k + n // k
print(c)


(a, b) = [int(x) for x in input().split()]
(m, n, c) = [a, 0, 0]
while m > 0:
	n += m
	(m, c) = [(m + c) // b, (m + c) % b]
print(n)


(a, b) = map(int, input().strip().split())
r = a
rem = 0
while a > 0:
	a += rem
	s = a // b
	r += s
	rem = a % b
	a = s
print(r)


(a1, b1) = input().split()
a = int(a1)
b = int(b1)
count = 0
c = 0
while c < a:
	count = count + 1
	if count == b:
		a = a + 1
		count = 0
	c = c + 1
print(a)


(a, b) = input().split(' ')
(a, b) = (int(a), int(b))
c = 0
h = 0
while a > 0:
	h += a
	c += a
	a = int(c / b)
	c = c % b
print(h)


(a, b) = list(map(int, input().split()))
h = 1
lo = 0
while True:
	a -= 1
	lo += 1
	if lo == b:
		a += 1
		lo = 0
	if a == 0:
		print(h)
		break
	h += 1


(a, b) = [int(i) for i in input().split()]
aa = 0
cnt = 0
while a:
	cnt += a
	aa += a
	a = aa // b
	aa = aa % b
print(cnt)


(a, b) = map(int, input().split(' '))
hours = a
wentOut = a
a = 0
while wentOut >= b:
	a = wentOut // b
	hours += a
	wentOut = wentOut % b + a
print(hours)


(a, b) = map(int, input().split())
e = a
while a >= b:
	e += a // b
	a = a // b + a % b
print(e)


(n, k) = input().split()
n = int(n)
k = int(k)

def cal(a, b):
	s = 0
	while a - b >= 0:
		a = a - b
		a += 1
		s += 1
	return s
print(cal(n, k) + n)


def main():
	cused = 0
	hours = 0
	cdisp = 0
	cused = 0
	ase = input()
	asee = ase.split(' ')
	a = int(asee[0])
	b = int(asee[1])
	cdisp += a
	while cdisp > 0:
		cused += 1
		cdisp -= 1
		hours += 1
		if cused == b:
			cused -= b
			cdisp += 1
	print(hours)
main()


arr = [0] * 2
arr = list(map(int, input().split()))
a = arr[0]
b = arr[1]
h = a
while a >= b:
	d = int(a / b)
	h += d
	m = a % b
	a = d + m
print(h)


(n, m) = [int(x) for x in input().split()]
re = n
c = 0
rem = 0
while re:
	re -= 1
	rem += 1
	if rem == m:
		re += 1
		rem = 0
	c += 1
print(c)


(a, b) = str(input()).split(' ')
a = int(a)
b = int(b)
miss = 0
value = a
while True:
	a += miss
	if a < b:
		break
	miss = a - int(a / b) * b
	a = int(a / b)
	value += a
print(value)


(old, b) = map(int, input().split())
hour = old
while old >= b:
	new = old // b
	hour += new
	left = old % b
	old = new + left
print(hour)


ab = list(map(int, input().split()))
a = ab[0]
b = ab[1]
s = a
while int(a / b) != 0:
	r = a % b
	a = int(a / b)
	s += a
	a += r
print(s)


(a, b) = input().split()
a = int(a)
b = int(b)
c = 0
sum = a
while a > 0:
	c += a % b
	a = int(a / b)
	if c >= b:
		a += int(c / b)
		c -= b
	sum += a
print(sum)


def main_function():
	(a, b) = [int(i) for i in input().split(' ')]
	counter = 0
	while True:
		if a < b:
			counter += a
			break
		a -= b
		a += 1
		counter += b
	return counter
print(main_function())


import sys
parametrs = list(map(int, input().split()))
n = parametrs[0]
b = parametrs[1]
hours = n
while n >= b:
	new_part = n // b
	hours += new_part
	n = n - new_part * b + new_part
print(hours)


(a, b) = map(int, input().strip().split(' '))
s = a
if a >= b:
	p = 1
else:
	p = 0
while a >= b:
	p = a // b
	w = a % b
	s += p
	a = p + w
print(s)


m = input().split(' ')
a = int(m[0])
b = int(m[1])
ch = 0
po = 0
while a > 0:
	ch += 1
	po += 1
	a -= 1
	if po == b:
		po = 0
		a += 1
print(ch)


(a, b) = input().strip('\n\r\t ').split(' ')
a = int(a)
b = int(b)
avail = a
burned = 0
count = 0
while avail > 0:
	count += 1
	avail -= 1
	burned += 1
	tmp = burned // b
	avail += tmp
	burned -= tmp * b
print(count)


n = input()
n = n.split()
a = int(n[0])
b = int(n[1])
c = []
count = a
for i in range(1, a + 1):
	if i % b == 0:
		count += 1
		if count % b == 0:
			count += 1
print(count)


(a, b) = map(int, input().split())
(hour, close) = (a, a)
while int(close // b) != 0:
	hour = hour + int(close // b)
	close = int(close // b) + close % b
print(hour)


(n, m) = map(int, input().split())
resp = 0
while n >= m:
	resp = resp + m
	n = n - m
	n = n + 1
resp = resp + n
print(resp)


(a, b) = input().split()
a = int(a)
b = int(b)

def new(x):
	if x < b:
		return 0
	else:
		count = int(x / b) + new(int(x / b) + x % b)
		return count
count = a + new(a)
print(int(count))


(a, b) = input().split()
a = int(a)
b = int(b)
t = a
n = 0
k = 0
while a > 0:
	a = a - 1
	n = n + 1
	k = k + 1
	if k % b == 0:
		a = a + 1
print(n)


(a, b) = list(map(int, input().split()))
hours = a
mark = 0
while a >= b:
	mark = a % b
	a = (a - mark) // b
	hours += a
	a += mark
print(hours)


def ans(n):
	if n < 1:
		return n
	else:
		return n + ans(n / m)
(n, m) = map(int, input().split())
print(int(ans(n)))


(a, b) = map(int, input().split())
cur_b = 0
counter = 0
while a > 0:
	counter += a
	cur_b += a
	(a, cur_b) = (cur_b // b, cur_b % b)
print(counter)


(a, b) = map(int, input().split())
hours = a
d = a
while True:
	if d >= b:
		hours += 1
		d -= b
		d += 1
	else:
		break
print(hours)


(a, b) = map(int, input().split())
r = 0
t = 0
while a + r >= b:
	t += a
	r += a % b
	a //= b
	if r >= b:
		(a, r) = (a + r // b, r % b)
print(t + a)


(sviecok, mrtvych) = map(int, input().split())
(naviac, hodin) = (sviecok // mrtvych, 0)
while naviac > 0:
	naviac = sviecok // mrtvych
	hodin += sviecok - sviecok % mrtvych
	sviecok %= mrtvych
	sviecok += naviac
else:
	hodin += sviecok
print(hodin)


from sys import stdin
(a, b) = (int(x) for x in stdin.readline().strip().split(' '))
result = a
while a >= b:
	result += int(a / b)
	a = int(a / b) + a - int(a / b) * b
print(result)


(m, n) = [int(i) for i in input().split()]
s = m + m // n
while m >= n:
	m = m % n + m // n
	s += m // n
print(s)


s = input('')
L = s.split()
a = int(L[0])
b = int(L[1])
tot = 0
while a >= b:
	c = a % b
	tot = tot + (a - c)
	a = c + (a - c) // b
tot = tot + a
print(tot)


import sys

class Scanner:

	def __init__(self):
		self.current_tokens = []

	def remaining_tokens(self):
		return len(self.current_tokens)

	def nextline(self):
		assert self.remaining_tokens() == 0, 'Reading next line with remaining tokens'
		return input()

	def nexttokens(self):
		return self.nextline().split()

	def nexttoken(self):
		if len(self.current_tokens) == 0:
			self.current_tokens = self.nexttokens()
		assert self.remaining_tokens() > 0, 'Not enough tokens to parse.'
		return self.current_tokens.pop(0)

	def nextints(self, n=-1):
		if n == -1:
			return list(map(int, self.nexttokens()))
		else:
			return (self.nextint() for i in range(n))

	def nextint(self):
		return int(self.nexttoken())

def quit():
	sys.exit(0)
stdin = Scanner()
nextint = stdin.nextint
nextints = stdin.nextints
nextline = stdin.nextline
(a, b) = nextints(2)
h = 0
while a > 0:
	h += 1
	a -= 1
	if h % b == 0:
		a += 1
print(h)


def f(a, b, c):
	if a == 0 and b > c:
		return 0
	elif a == 0 and b <= c:
		return f(c // b, b, c % b)
	else:
		return a + f(a // b, b, c + a % b)
x = input().split()
a = int(x[0])
b = int(x[1])
print(f(a, b, 0))


(a, b) = map(int, input().split())
sum1 = a
while a >= b:
	re = int(a / b)
	a = re + a % b
	sum1 = sum1 + re
print(sum1)


(a, b) = map(int, input().split())
sum = 0
sum += a
while True:
	c = a // b
	sum += c
	o = a % b
	c = c + o
	if c < b:
		break
	else:
		a = c
print(sum)


(a, b) = [int(i) for i in input().split()]

def calc(a, b, count=0):
	if a < b and a >= 0:
		count += a
		return count
	elif a >= 0:
		return calc(a - b + 1, b, count) + b
print(calc(a, b, count=0))


(a, b) = [int(x) for x in input().split()]
candles_off = a
nb_candles = a
while candles_off > 0:
	if candles_off >= b:
		nb_candles += int(candles_off / b)
		candles_off = int(candles_off / b) + candles_off % b
	else:
		break
print(nb_candles)


(in0, in1) = [int(x) for x in input().split()]
(in2, in3) = (in0, 0)
while in0 != 0:
	in3 = in0 % in1
	in0 //= in1
	in2 += in0
	if in0 > 0:
		in0 += in3
print(in2)


nm = [int(i) for i in input().split()]
n = nm[0]
m = nm[1]
runout = 0
hours = 0
while n != 0:
	hours += n
	runout += n
	n = runout // m
	runout -= runout // m * m
print(hours)


(a, b) = [int(i) for i in input().split()]
C = 0
RES = 0
while a > 0:
	RES += a
	(a, C) = ((a + C) // b, (a + C) % b)
print(RES)


import sys
import math
from sys import stdin, stdout

def get_ints_in_variables():
	return map(int, sys.stdin.readline().strip().split())

def get_int():
	return int(input())

def get_ints_in_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_list_of_list(n):
	return [list(map(int, sys.stdin.readline().strip().split())) for _ in range(n)]

def get_string():
	return sys.stdin.readline().strip()

def main():
	(a, b) = get_ints_in_variables()
	count = a
	while int(a / b) != 0:
		count += int(a / b)
		a = int(a / b) + a % b
	print(count)
main()


(a, b) = list(map(int, input().split()))
count = a
while a >= b:
	remaining = a // b
	count += remaining
	remainder = a % b
	a = remaining + remainder
print(count)


def seperateints(x):
	k = ''
	l = []
	for i in x:
		if i == ' ':
			l.append(int(k))
			k = ''
			continue
		k = k + i
	l.append(int(k))
	return l

def luckynum(x):
	for i in x:
		if i != '4' and i != '7':
			return False
	return True
l = seperateints(input())
n = l[0]
if l[0] >= l[1]:
	while True:
		if l[0] % l[1] == 0:
			l[0] = l[0] // l[1]
			n = n + l[0]
		else:
			x = l[0] // l[1]
			l[0] = x + l[0] % l[1]
			n = n + x
		if l[0] < l[1]:
			break
print(n)


import sys
from bisect import bisect_left, bisect_right, insort
from collections import deque, Counter
from math import gcd, sqrt, factorial, ceil, log10, log2
from itertools import permutations
from heapq import heappush, heappop, heapify
inf = float('inf')
mod = 1000000007

def factorial_p(n, p):
	ans = 1
	if n <= p // 2:
		for i in range(1, n + 1):
			ans = ans * i % p
	else:
		for i in range(1, p - n):
			ans = ans * i % p
		ans = pow(ans, p - 2, p)
		if n % 2 == 0:
			ans = p - ans
	return ans

def nCr_p(n, r, p):
	ans = 1
	while n != 0 or r != 0:
		(a, b) = (n % p, r % p)
		if a < b:
			return 0
		ans = ans * factorial_p(a, p) * pow(factorial_p(b, p), p - 2, p) * pow(factorial_p(a - b, p), p - 2, p) % p
		n //= p
		r //= p
	return ans

def prime_sieve(n):
	flag = n % 6 == 2
	sieve = bytearray((n // 3 + flag >> 3) + 1)
	for i in range(1, int(n ** 0.5) // 3 + 1):
		if not sieve[i >> 3] >> (i & 7) & 1:
			k = 3 * i + 1 | 1
			for j in range(k * k // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
			for j in range(k * (k - 2 * (i & 1) + 4) // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
	return sieve

def prime_list(n):
	res = []
	if n > 1:
		res.append(2)
	if n > 2:
		res.append(3)
	if n > 4:
		sieve = prime_sieve(n + 1)
		res.extend((3 * i + 1 | 1 for i in range(1, (n + 1) // 3 + (n % 6 == 1)) if not sieve[i >> 3] >> (i & 7) & 1))
	return res

def binary(number):
	result = 0
	while number:
		result = result + 1
		number = number & number - 1
	return result

def is_prime(n):
	if n < 5 or n & 1 == 0 or n % 3 == 0:
		return 2 <= n <= 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			p = p * p % n
			if p == n - 1:
				break
		else:
			return False
	return True

def all_factors(n):
	(small, large) = ([], [])
	for i in range(1, int(n ** 0.5) + 1, 2 if n & 1 else 1):
		if not n % i:
			small.append(i)
			large.append(n // i)
	if small[-1] == large[-1]:
		large.pop()
	large.reverse()
	small.extend(large)
	return small

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
(a, b) = get_ints()
if b > a:
	print(a)
elif a == b:
	print(a + 1)
else:
	total = a
	while a // b >= 1:
		extra = a % b
		a -= extra
		total += a // b
		a = a // b + extra
	print(total)


(a, b) = map(int, input().split())
count = a
while 1:
	d = a // b
	count += d
	rem = a % b
	a = d + rem
	if a < b:
		break
print(count)


from __future__ import division, print_function
from collections import *
from math import *
from itertools import *
from time import time
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	(a, b) = map(int, input().split())
	dummy = a
	overall_hours = a
	while True:
		if dummy >= b:
			dummy2 = dummy % b
			dummy //= b
			overall_hours += dummy
			dummy += dummy2
		else:
			break
	print(overall_hours)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(a, b) = map(int, input().split())
s = (a * b - 1) // (b - 1)
print(s)


(a, b) = [int(x) for x in input().split()]
x = a
while a >= b:
	p = a // b
	q = a - b * (a // b)
	x = x + p
	a = p + q
else:
	print(x)


(burning, eff) = map(int, input().split())
times = 0
extra = 0
while burning > 0:
	times += burning
	tmp = burning + extra
	extra = tmp % eff
	burning = (tmp - extra) // eff
print(times)


(a, b) = [int(x) for x in input().split()]
count = a
res = a
while res >= b:
	count += res // b
	res = res // b + res % b
print(count)


candles = input().split()
original_candles = int(candles[0])
new_candles = int(candles[1])
used_candles = original_candles
wax_left = original_candles
while wax_left - new_candles >= 0:
	used_candles = used_candles + 1
	wax_left = wax_left - new_candles + 1
print(used_candles)


(n, m) = map(int, input().split())
ans = 0
while n != 0:
	n -= 1
	ans += 1
	if ans % m == 0:
		n += 1
print(ans)


(X, Total) = (list(map(int, input().split())), 0)
if X[1] > X[0]:
	print(X[0])
	exit()
(Total, X[0]) = (Total + X[1], X[0] - X[1])
while X[0] // (X[1] - 1) >= 1:
	(Total, X[0]) = (Total + X[1], X[0] - X[1] + 1)
print(Total + X[0] + 1)


(a, b) = [int(x) for x in input().split()]
ans = 0
while a >= b:
	ans += b * (a // b)
	a = a // b + a % b
ans += a
print(ans)


def svechi(a, b):
	result = a
	while a >= b:
		a -= b - 1
		result += 1
	return result
(A, B) = [int(i) for i in input().split()]
print(svechi(A, B))


from math import *
(a, b) = map(int, input().split())
print(floor(a * (1 / (1 - 1 / b)) - 1e-05))


(candle, b) = [int(x) for x in input().split()]
hours = 0
burnt_out = 0
while True:
	if candle <= 0:
		break
	hours += candle
	burnt_out += candle
	candle = int(burnt_out / b)
	burnt_out = burnt_out % b
print(hours)


(m, n) = map(int, input().split())
s = m
while m >= n:
	s += m // n
	m = m // n + m % n
print(s)


(a, b) = map(int, input().split())
z = 0
out = 0
while a != 0:
	out += a
	(z, a) = ((a + z) % b, (a + z) // b)
print(out)


(a, b) = map(int, input().split())
pr = 0
time = 0
while a > 0:
	time += 1
	a = a - 1
	pr += 1
	if pr == b:
		a += 1
		pr = 0
print(time)


(a, b) = map(int, input().split())
output = a
left = a
while left >= b:
	output = output + left // b
	left = left // b + left % b
print(output)


def main():
	(a, b) = map(int, input().split())
	hours = a
	spare = a
	while spare >= b:
		new = spare // b
		hold = spare % b
		hours += new
		spare = hold + new
	print(hours)
main()


(n, m) = map(int, input().split())
c = n
while n >= m:
	k = int(n % m)
	n = n // m
	c = c + n
	n = k + n
print(int(c))


Datos = input()
Datos = Datos.split()
a = int(Datos[0])
b = int(Datos[1])
hora = 0
cont = 0
while a >= b:
	if a % b == 0:
		hora += a
		a = a // b
	else:
		cont += a % b
		hora += a
		a = a // b
		if cont >= b:
			a += 1
			cont = cont % b
hora += a
if a + cont >= b:
	hora += 1
print(hora)


(a, b) = map(int, input().split())
total = 0
while a > 0:
	total = total + 1
	a = a - 1
	if total % b == 0:
		a = a + 1
print(total)


(a, b) = map(int, input().split())
k = a
while a >= b:
	os = a % b
	a //= b
	k += a
	a += os
print(k)


(a, b) = map(int, input().split())
n = a
sum = 0
while a >= b:
	c = a // b
	d = a % b
	sum += c
	a = c + d
print(n + sum)


(candle, k) = tuple(map(int, input().split()))
ans = 0
rem = 0
while candle != 0:
	ans += candle
	new_candle = (candle + rem) // k
	rem = (candle + rem) % k
	candle = new_candle
print(ans)


(container, b) = map(int, input().split())
day = 0
burnt = 0
while container != 0:
	container -= 1
	day += 1
	burnt += 1
	if burnt == b:
		container += 1
		burnt = 0
print(day)


(a, b) = list(map(int, input().split()))
total = a
left = 0
while a > 0:
	total += a // b
	a = a % b + a // b
	if a // b == 0:
		break
print(total)


(a, b) = input().split()
a = int(a)
b = int(b)
hour = 0
count = a
n = 0
while count != 0:
	count = count - 1
	hour = hour + 1
	n = n + 1
	while n == b:
		count = count + 1
		n = 0
print(hour)


a = input().split()
(a, b) = (int(a[0]), int(a[1]))
(t, pot) = (0, 0)
for i in range(a):
	t += 1
	pot += 1
while pot // b != 0:
	t += 1
	pot -= b
	pot += 1
print(t)


(n, m) = list(map(int, input().split()))
ans = 0
sr = 0
used = 0
new = n
while True:
	ans = ans + new
	used = new + sr
	if used < m:
		break
	new = used // m
	sr = used % m
print(ans)


(n, m) = (int(i) for i in input().split())
days = n
rem = 0
while n:
	rem += n % m
	n = n // m
	n += rem // m
	rem = rem % m
	days += n
print(days)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
import sys
input = sys.stdin.readline
scan_int = lambda : int(input())
scan_string = lambda : input().rstrip()
read_list = lambda : list(read())
read = lambda : map(int, input().split())
read_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def is_integer(n):
	return math.ceil(n) == math.floor(n)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def next_prime(n, primes):
	while primes[n] != True:
		n += 1
	return n
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(beauty, s, n, count):
	pass
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
alphs = 'abcdefghijklmnopqrstuvwxyz'.upper()
from itertools import permutations
import math
import bisect as bis
import random
import sys
import collections as collect

def solve():
	(a, b) = read()
	s = 0
	rem = 0
	while a > 0:
		s += a
		a += rem
		rem = a % b
		a //= b
	print(s)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for i in range(1):
	solve()


n = [int(i) for i in input().split(' ')]
a = n[0]
b = n[1]
count = 0
while a >= b:
	a = a - b + 1
	count += b
count += a
print(count)


(a, b) = map(int, input().split())
x = 0
while a > 0:
	a = a - 1
	x = x + 1
	if x % b == 0:
		a = a + 1
print(x)


(a, b) = list(map(int, input().split()))
res = a
off = a
while off >= b:
	(on, off) = divmod(off, b)
	res += on
	off += on
print(res)


(a, b) = map(int, input().split())
num_hours = a
while True:
	if a < b:
		break
	num_hours += a // b
	a = a // b + a % b
print(num_hours)


def candles(a, b):
	c = a
	while a >= b:
		c += a // b
		x = a % b
		a //= b
		a += x
	return c
(a, b) = input().split()
(a, b) = (int(a), int(b))
print(candles(a, b))


(candl, new_candl) = map(int, input().split())
result = candl
bad_candls = candl
candl = 0
while True:
	if bad_candls % new_candl == 0:
		candl = int(bad_candls / new_candl)
		bad_candls = 0
	else:
		candl = int(bad_candls / new_candl)
		bad_candls = bad_candls % new_candl
	result += candl
	bad_candls += candl
	candl = 0
	if bad_candls < new_candl:
		break
print(result)


(a, b) = map(int, input().split())
hours = a
rem = 0
while a >= b:
	temp = a // b
	hours += temp
	rem = a % b
	a = temp + rem
print(hours)


(x, y) = map(int, input().split(' '))
u = x / y + x % y
j = 0
while u >= y:
	p = int(u / y)
	u = p + u % y
	j = j + p
w = int(x + x / y + j)
print(w)


s = input().split()
a = int(s[0])
b = int(s[1])
f = 0
ost = a
k = a
while ost // b >= 1:
	f = ost // b
	ost = ost - b * f
	k = k + f
	ost = ost + f
print(k)


(a, b) = [int(i) for i in input().split()]
t = a
while t // b > 0:
	a += t // b
	t = t // b + t % b
print(a)


vas = input().split(' ')
cand = int(vas[0])
re = int(vas[1])
ccand = cand
T = True
firsttime = True
while T:
	resto = ccand % re
	ccand = ccand // re + resto
	cand += ccand - resto
	resto = 0
	if ccand // re == 0:
		T = False
print(cand)


(n, m) = map(int, input().split())
day = 0
while n > 0:
	day += 1
	if day % m == 0:
		n += 1
	else:
		n = n
	n -= 1
else:
	print(day)


(a, b) = map(int, input().split())
burnt = 0
t = 0
while a > 0:
	t += a
	burnt += a
	a = burnt // b
	burnt = burnt % b
print(t)


(a, b) = map(int, input().split())
hours = 0
left = a
while left > 0:
	hours += 1
	left -= 1
	if hours % b == 0:
		left += 1
print(hours)


ab = input().split()
a = int(ab[0])
b = int(ab[1])
i = a
r = 0
count = 0
while i > 0:
	count += i
	q = i // b
	r += i % b
	if r // b > 0:
		q += r // b
		r %= b
	i = q
print(count)


(a, b) = list(map(int, input().split()))
hours = a
ost = 0
while a > 0:
	a2 = a + ost
	a = (a + ost) // b
	ost = a2 % b
	hours += a
print(hours)


x = input().split()
a = int(x[0])
b = int(x[1])
i = 0
z = 0
c = a
for i in range(a - 1):
	c = c - b + 1
	if c > 0:
		z += 1
	i += 1
print(z + a)


Candle_input = input('')
Candle_input = Candle_input.split(' ')
remaining_total = int(Candle_input[0])
recharge = int(Candle_input[1])
hours_of_light = 0
while remaining_total > 0:
	if remaining_total >= recharge:
		remaining_total = remaining_total - recharge
		hours_of_light = hours_of_light + recharge
		remaining_total = remaining_total + 1
	else:
		hours_of_light = hours_of_light + remaining_total
		remaining_total = 0
print(hours_of_light)


import math
(a, b) = map(int, input().split())
c = 0
day = 0
while a > 0:
	a -= 1
	day += 1
	c += 1
	if c == b:
		a += 1
		c = 0
print(day)


def main():
	(n, div) = map(int, input().split())
	somme = 0
	morceauRestant = 0
	while n != 0:
		somme += n
		morceau = morceauRestant + n
		n = morceau // div
		morceauRestant = morceau % div
	print(somme)
main()


def candles(a, b):
	a1 = a // b
	if a == b:
		return 1
	elif a < b:
		return 0
	else:
		a = a - a // b * b + a // b
		return a1 + candles(a, b)
(a1, b1) = input().split()
a = int(a1)
b = int(b1)
print(a + candles(a, b))


(a, b) = [int(x) for x in input().split()]
count = a

def burn(a, b, count):
	if a < b:
		return count
	else:
		count += a // b
		a = a // b + a % b
		return burn(a, b, count)
ans = burn(a, b, count)
print(ans)


import sys
p = sys.stdin.readline().strip().split(' ')
h = 0
a = int(p[0])
b = int(p[1])
m = 0
while a + m >= b:
	h = h + a
	t = (a + m) // b
	m = (a + m) % b
	a = t
print(h + a)


(a, b) = map(int, input().split())
d = a
t = 0
while a >= b:
	c = a // b
	e = a - b * c
	a = c + e
	t += e
	d += c
print(d)


def Candles(a, b):
	res = a
	r = a % b
	while a > 0:
		a = a // b
		r = r + a % b
		res = res + a
	a = r
	while r >= b:
		r = a % b
		while a > 0:
			a = a // b
			r = r + a % b
			res = res + a
		a = r
	return res
(a, b) = input().split()
a = int(a)
b = int(b)
print(Candles(a, b))


info = input().split()
(a, b) = [int(i) for i in info]
used = a
while a >= b:
	new = a // b
	a = a // b + a - a // b * b
	used += new
print(used)


(a, b) = map(int, input().split())
s = a
t = a
while t >= b:
	r = t % b
	t = t // b
	s = s + t
	t = t + r
print(s)


from sys import stdin
(a, b) = map(int, stdin.readline().split())
(res, tail) = (a, 0)
while a:
	(a, tail) = divmod(a + tail, b)
	res += a
print(res)


(a, b) = map(int, input().split())

def f(x, y):
	if x < y:
		return x
	return y * (x // y) + f(x - y * (x // y) + x // y, y)
print(f(a, b))


def _379A(a, b):
	no_of_hours = a
	while a // b > 0:
		no_of_hours += a // b
		a = a // b + a % b
	return no_of_hours
(a, b) = list(map(lambda x: int(x), input().split()))
print(_379A(a, b))


x = input()
x = x.split()
candles = int(x[0])
temp = candles
re = int(x[1])
flag = 0
while candles >= re:
	candles = candles - re
	candles = candles + 1
	flag = flag + 1
print(temp + flag)


[a, b] = list(map(int, input().split()))
h = 0
c = a
des = 0
flag = True
while flag:
	if des == b:
		c += 1
		des -= b
	if c == 0:
		flag = False
	else:
		c -= 1
		h += 1
	des += 1
print(h)


import os
import sys
import math
import collections

def get_int():
	return int(input())

def get_ints():
	return map(int, input().split())

def get_strs():
	return input().split()

def get_float():
	return float(input())

def get_floats():
	return map(float, input().split())

def list_strs():
	return list(input().split())

def list_ints():
	return list(map(int, input().split()))

def list_floats():
	return list(map(float, input.split()))

def post(x):
	print(x, end=' ')
(a, b) = get_ints()
res = a
mod = 0
diff = 0
while a >= b:
	diff = a // b
	res += diff
	mod = a % b
	a = diff + mod
print(res)


(a, b) = map(int, input().split())
check = True
i = 0
while check:
	i += 1
	a -= 1
	if i % b == 0:
		a += 1
	if a == 0:
		check = False
print(i)


(a, b) = input().split()
a = int(a)
b = int(b)
candles = a
stumps = 0
hours = 0
while candles > 0:
	candles -= 1
	stumps += 1
	hours += 1
	if stumps == b:
		stumps = 0
		candles += 1
print(hours)


(a, b) = map(int, input().split())
t = a
out = a
while out // b != 0:
	t += out // b
	out = out - out // b * b + out // b
print(t)


(a, b) = map(int, input().split())
i = 0
while a > 0:
	i += 1
	a -= 1
a = i
while a > 0 and a >= b:
	i = i + a // b
	a = a // b + a % b
print(i)


(a, b) = map(int, input().split())
c = (a - 1) // (b - 1)
print(a + c)


import math
(a, b) = [int(i) for i in input().split()]
c = int(a / b)
temp = c
d = a + c
sisa = a - c * b
asd = []
e = 0
for i in range(c + 5):
	c += sisa
	sisa = 0
	if c >= b:
		e = c
		c = int(c / b)
		asd.append(c)
		sisa = e - c * b
	else:
		break
print(d + sum(asd))


(a, b) = map(int, input().split(' '))
res = 0
sub = 0
while a > 0:
	a -= 1
	res += 1
	sub += 1
	if sub == b:
		a += 1
		sub = 0
print(res)


(a, b) = [int(i) for i in input().split()]
sum = a
while 1:
	c = int(a / b)
	a = c + int(a % b)
	sum = sum + c
	if a < b:
		break
print(sum)


(a, b) = map(int, input().split())
sumh = a
while a >= 1:
	sumh = sumh + a / b
	a = a / b
print(int(sumh))


(n, m) = map(int, input().split())
k = n
p = n
if n < m:
	print(k)
elif n == m:
	print(k + 1)
else:
	while p >= m:
		k += p // m
		p = p // m + p % m
	print(k)


def Main():
	(a, b) = map(int, input().split())
	ans = 0
	while a >= b:
		rem = a % b
		ans += a - rem
		a //= b
		a += rem
	ans += a
	print(ans)
Main()


x = input().split()
a = int(x[0])
b = int(x[1])
res = (a - 1) // (b - 1) + a
print(res)


a = input().split()
b = int(a[1])
a = int(a[0])
answ = 0
x = 0
while a != 0:
	a -= 1
	answ += 1
	x += 1
	if x == b:
		x = 0
		a += 1
print(answ)


(a, b) = [int(x) for x in input().split()]
n = a
m = a
r = 0
p = 0
while m > b - 1:
	r = m - int(m / b) * b
	p = int(m / b)
	m = p + r
	n = n + p
print(n)


(full, n) = [int(i) for i in input().split()]
half = 0
hours = 0
while full > 0:
	hours = hours + full
	half = half + full
	full = half // n
	half = half - half // n * n
print(hours)


(a, b) = map(int, input().split())
r = 0
z = 0
while a:
	r += a
	z += a % b
	a //= b
	if z >= b:
		a += z // b
		z %= b
print(r)


numbers = list(map(int, input().split()))
a = numbers[0]
b = numbers[1]
hours = a
rest = a
while a != 0:
	a = rest // b
	hours += a
	rest = a + rest % b
print(hours)


(a, b) = map(int, input().split())
z = a
cand = a
while z >= b:
	e = z % b
	z = z // b
	cand += z
	z += e
print(cand)


(a, b) = [int(a) for a in input().split()]
hrs = a
flag = True
rem = 0
while flag:
	if a >= b:
		s = a // b
		hrs += s
		rem = a % b
		a = s + rem
	else:
		flag = False
print(hrs)


(a, b) = map(int, input().split())
x = a
while True:
	d = x // b
	z = x % b
	a += d
	x = d + z
	if d == 0:
		break
print(a)


(a, b) = map(int, input().split())
t = 0
u = 0
while True:
	u += a
	t += a
	a = u // b
	u -= a * b
	if a == 0:
		print(t)
		break


import sys
import math
import bisect

def main():
	ans = 0
	r = 0
	(n, m) = map(int, input().split())
	while n:
		ans += n
		r += n
		(n, r) = (r // m, r % m)
	print(ans)
main()


(a, b) = map(int, input().split())
c = 0
m = 0
while a != 0:
	c += a
	m += a
	a = m // b
	m = m % b
print(c)


def solve():
	(a, b) = [int(x) for x in input().split()]
	res = a
	while a // b > 0:
		extra = a % b
		a = a // b
		res += a
		a += extra
	print(res)
	return
solve()


def qc(n, b):
	(t, z) = (0, 0)
	while n > 0:
		t += n
		n = t // b - z
		z += n
	return t
(n, b) = [int(x) for x in input().split()]
print(qc(n, b))


(a, b) = [int(i) for i in input().split()]
s = a
while 1:
	s = int(s + a / b)
	a = int(a / b + a % b)
	if a < b:
		break
print(int(s))


anb = input().split()
a = int(anb[0])
b = int(anb[1])
time = a
Pos = True
while Pos:
	if a // b != 0:
		time += a // b
		a = a // b + a % b
	else:
		Pos = False
print(time)


(a, b) = [int(x) for x in input().split()]
c = 0
stubs = 0
while a > 0:
	c += a
	stubs += a
	a = stubs // b
	stubs = stubs % b
print(c)


n = input()
n = n.split()
m = int(n[1])
n = int(n[0])
c = 0
while n > 0:
	c += 1
	n -= 1
	if c % m == 0:
		n += 1
print(c)


s = 0
(a, b) = map(int, input().strip().split()[:2])
k = a
while a >= b:
	p = a // b
	s += p
	a = p + a % b
print(k + s)


def solver(candles: int, to_reproduce: int):
	count = 0
	while candles >= to_reproduce:
		candles = candles - to_reproduce + 1
		count += 1
	return count
st = input()
list = [int(s) for s in st.split() if s.isdigit()]
candles = list[0]
to_reproduce = list[1]
if candles >= to_reproduce:
	print(solver(candles, to_reproduce) + candles)
else:
	print(candles)


(x, y) = map(int, input().split(' '))
a = 0
c = 0
while x > 0.1:
	a += x
	x = x / y
	pass
print(int(a))


ab = list(map(int, input().split()))
hours = 0
fireless = 0
while ab[0] > 0:
	hours += ab[0]
	fireless += ab[0]
	ab[0] = fireless // ab[1]
	fireless -= fireless // ab[1] * ab[1]
print(hours)


(n, m) = map(int, input().split())
i = 0
c = 0
ans = n
while n >= m:
	c = 0
	while n >= m:
		n = n - m
		c += 1
	n = n + c
	ans += c
print(ans)


import math

def inp():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
(a, b) = invr()
hr = a
hate = 0
pora = a
while True:
	new_candle = pora // b
	hate = pora % b
	hr += new_candle
	pora = new_candle + hate
	if pora < b:
		break
print(hr)


(a, b) = (int(s) for s in input().split())
sum = 0
while a >= b:
	sum += b
	a -= b - 1
print(sum + a)


def calculate_hour(candles: int, pieces: int) -> int:
	hour = 0
	went_outs = 0
	while candles > 0:
		hour += candles
		went_outs += candles
		candles = went_outs // pieces
		went_outs %= pieces
	return hour
(a, b) = map(int, input().split())
print(calculate_hour(a, b))


(a, b) = [int(x) for x in input().split()]
hour = 0
while a >= 1:
	hour += 1
	a -= 1
	if hour % b == 0:
		a += 1
print(hour)


(n, k) = map(int, input().split())
s = 0
while n > 0:
	s += min(n, k)
	n -= k
	n += 1
print(s)


(a, b) = map(int, input().split())
count = a
while a >= b:
	count += a // b
	a = a // b + a % b
print(count)


def main():
	(a, b) = input().split()
	(a, b) = (int(a), int(b))
	i = 1
	while i <= a:
		if i % b == 0:
			a += 1
		i += 1
	print(a)
main()


(n, k) = [int(x) for x in input().split()]
counter = n
while n >= k:
	counter += n // k
	n = n // k + n % k
print(counter)


(a, b) = input().split()
x = int(a)
a1 = int(a)
b1 = int(b)
while a1 >= b1:
	x = x + a1 // b1
	a1 = a1 // b1 + a1 % b1
print(x)


(a, b) = input().split()
count = 0
a = int(a)
b = int(b)
m = a
rem = 0
while a != 0:
	count += a // b
	rem += a % b
	a = a // b
	if a == 0 and rem >= b:
		a = rem
		rem = 0
print(count + m)


import math
(a, b) = map(int, input().split())
candles = a
rem = 0
for i in range(math.floor(math.log(a, b)) + 1):
	candles += a // b
	a = a // b + a % b
print(candles)


(a, b) = map(int, input().split())
s = 0
s += a
if a // b > 0:
	while a >= b:
		t = a % b
		a //= b
		s += a
		a += t
print(s)


a = str(input(''))
b = a.split(' ')
c = int(b[0])
d = int(b[1])
x = int(c / d)
rem = c % d
sum1 = c
while x > 0:
	sum1 = sum1 + x
	rem = rem + x % d
	x = int(x / d)
rem1 = rem % d
if rem > 0:
	while rem > 0:
		sum1 = sum1 + rem / d
		rem1 = rem1 + rem % d
		rem = int(rem / d)
print(int(sum1))


(a, b) = map(int, input().split())
total = 0
residual = 0
while a != 0:
	total += a
	residual += a % b
	a = a // b
	if residual >= b:
		a += residual // b
		residual = residual % b
print(total)


(a, b) = input().split()
a = int(a)
b = int(b)
cnt = 0
rem = 0
while a != 0:
	rem = rem + a % b
	if rem >= b:
		cnt += rem // b
		rem = rem % b + rem // b
	cnt += a
	a //= b
print(cnt)


abStr = input()
a = int(abStr.split()[0])
b = int(abStr.split()[1])
time = 0
while a >= b:
	a = a - b
	a = a + 1
	time = time + b
time = time + a
print(time)


line = input().split()
a = int(line[0])
b = int(line[1])
n = a
m = 0
while True:
	a0 = a
	a = (a0 + m) // b
	if a == 0:
		break
	n += a
	m = (a0 + m) % b
print(n)


(a, b) = (int(x) for x in input().split())
t = 0
bo = 0
while a > 0:
	a -= 1
	bo += 1
	if bo == b:
		a += 1
		bo = 0
	t += 1
print(t)


(a, b) = map(int, input().split())
hours = 0
went_out = 0
while a > 0:
	hours += a
	went_out += a
	a = int(went_out / b)
	went_out = went_out % b
print(hours)


(a, b) = map(int, input().split())
sum = a
while a >= b:
	div = a // b
	sum = sum + div
	rem = a % b
	a = div + rem
print(sum)


num = [int(i) for i in input().split()]
a = num[0]
b = num[1]
t = int(a / b)
c = 0
pro = a
while int(a / b) != 0:
	pro = pro + int(a / b)
	c = a % b
	a = int(a / b) + c
print(pro)


(n, t) = map(int, input().split())
day = 1
while n > 0:
	if day % t == 0:
		n += 1
	day += 1
	n -= 1
print(day - 1)


(candels, b) = [int(data) for data in input().split()]
hours = candels
candels_ends = candels
while candels_ends >= b:
	candels = candels_ends // b
	candels_ends = candels_ends - candels * b
	hours = hours + candels
	candels_ends = candels_ends + candels
print(hours)


a = [int(i) for i in input().split()]
sum = 0
sum += a[0]
b = sum
while b != 0:
	if b >= a[1]:
		b -= a[1]
		b += 1
		sum += 1
	else:
		b -= b
print(sum)


(a, b) = map(int, input().split())
(result, c) = (0, 0)
while a:
	result += a
	c += a
	a = c // b
	c %= b
print(result, end='')


array = list(map(int, input().split()))
(a, b) = (array[0], array[1])
counter = 0
while True:
	if a < b:
		counter += a
		break
	else:
		counter += b
		a -= b - 1
print(counter)


(a, b) = [int(i) for i in input().split()]
r = a
while a // b > 0:
	r = r + a // b
	a = a % b + a // b
print(r)


(a, b) = map(int, input().split())
ans = a
p = a
while p // b > 0:
	ans += p // b
	p = p % b + p // b
print(ans)


s = input()
s = s.split()
s = [int(x) for x in s]
a = s[0]
b = s[1]
i = 0
while a > 0:
	i = i + 1
	a = a - 1
	if i % b == 0:
		a = a + 1
print(i)


from sys import stdin
input = stdin.readline

def candle(a, b, c=0):
	t = a
	while a >= b:
		while a:
			c += a % b
			a //= b
			t += a
		a = c
		c = 0
	return t
print(candle(*map(int, input().split())))


licznik = 0

def robienie(a, b):
	d = a - b * (a // b)
	c = a // b
	global licznik
	if c > 0:
		licznik += c
		return robienie(c + d, b)
	else:
		return licznik
x = input()
lista = x.split(' ')
wynik = int(lista[0]) + robienie(int(lista[0]), int(lista[1]))
print(wynik)


(a, b) = map(int, input().split())
q = 0
while a > 0:
	a -= 1
	q += 1
	if q % b == 0:
		a += 1
print(q)


(a, b) = map(int, input().split())
result = a
counter = 0
while a >= b:
	a -= b
	a += 1
	counter += 1
print(counter + result)


(a, b) = map(int, input().split())
hrs = a
melt = a
while melt >= b:
	hrs += melt // b
	melt = melt % b + melt // b
print(hrs)


(a, b) = map(int, input().split())
total = 0
burned = 0
while a > 0:
	total += a
	burned += a
	a = burned // b
	burned = burned % b
print(total)


(n, m) = map(int, input().split())
sm = n
while n >= m:
	sm += n // m
	n = n // m + n % m
print(sm)


(a, b) = map(int, input().split())
h = a
while True:
	h += a // b
	a = a // b + a % b
	if a < b:
		break
print(h)


(a, b) = map(int, input().split())
hor = 0
sgor = 0
while a > 0:
	hor += 1
	a -= 1
	sgor += 1
	if sgor == b:
		a += 1
		sgor -= b
print(hor)


(a, b) = map(int, input().split())
t = a
while a >= b:
	q = a // b
	r = a % b
	t += q
	a = q + r
print(t)


(a, b) = map(int, input().split())

def solve(rem, grp):
	if rem < grp:
		return 0
	candies = rem // grp
	return candies + solve(rem // grp + rem % grp, grp)
ans = a + solve(a, b)
print(ans)


(a, b) = map(int, input().split(' '))
cou = a
while a >= b:
	cou += a // b
	a = a // b + a % b
print(cou)


(n, m) = map(int, input().split())
ans = 0
i = 0
while True:
	n -= 1
	i += 1
	ans += 1
	if i == m:
		i = 0
		n += 1
	if n == 0:
		break
print(ans)


(n, m) = map(int, input().split())
candles = []
for i in range(1, n + 1):
	candles.append(i)
for item in candles:
	if item % m == 0:
		n = n + 1
		candles.append(n)
print(max(candles))


import math
import os
import sys
import re
import itertools
import functools
import operator

def res(a, b, c):
	return a + res((a + c) // b, b, (a + c) % b) if a != 0 else 0
(a, b) = map(int, input().split())
print(res(a, b, 0))


(a, b) = [int(i) for i in input().split()]
res = a
while a >= b:
	a -= b
	a += 1
	res += 1
print(int(res))


(a, b) = map(int, input().split())
n = a
p = a
y = 0
while n > b:
	x = n // b
	p += x
	n = x + n % b
print(p + n // b)


from sys import stdin, stdout
from math import ceil, floor, sqrt
from collections import deque, Counter
inp = stdin.readline
out = stdout.write
(a, b) = map(int, inp().strip().split())
c = (a * b - 1) // (b - 1)
print(c)


(a, b) = input().split(' ')
a = int(a)
b = int(b)
cnt = a
while a >= b:
	cnt = cnt + int(a / b)
	a = int(a / b) + a % b
print(cnt)


(x, y) = map(int, input().split(' '))
q = 0
t = x
i = 0
while t != 0:
	i += t
	x = t
	t = (x + q) // y
	q = (x + q) % y
print(i)


(n, a) = map(int, input().split())
t = 0
while n >= a:
	n = n - a + 1
	t += a
t += n
print(t)


(n, m) = map(int, input().split())
c = n // m
b = n % m
i = n
while c > 0:
	i = i + c
	c = c + b
	b = c % m
	c = c // m
print(i)


def squizer(candels):
	global b
	global answer
	global ost
	while candels >= b:
		ost.append(candels % b)
		candels = candels // b
		answer.append(candels)
	ost.append(candels)
(a, b) = list(map(int, input().split()))
ost = []
answer = [a]
squizer(a)
c = sum(ost)
while c >= b:
	ost.clear()
	squizer(c)
	c = sum(ost)
print(sum(answer))


def main():
	(a, b) = tuple(map(int, input().rstrip().split()))
	ans = a
	while a >= b:
		ans += a // b
		a = a // b + a % b
	print(ans)
main()


(a, b) = map(int, input().split())
t = 0
prev = 0
while a != 0:
	t += a
	(a, prev) = ((a + prev) // b, (a + prev) % b)
print(t)


(a, b) = map(int, input().split())
t = 0
t += a
while a >= b:
	n = a % b
	a //= b
	t += a
	a += n
print(t)


(sum_in, ex) = [int(x) for x in input().strip().split()]
cnt = sum_in
while sum_in >= ex:
	cnt += int(sum_in / ex)
	sum_in = int(sum_in / ex) + sum_in % ex
print(cnt)


(a, b) = map(int, input().split())
res = a
while a >= b:
	d = a // b
	res += d
	m = a % b
	a = d + m
print(res)


(a, b) = map(int, input().split())
ost = 0
ans = 0
while a > 0:
	ost += a
	ans += a
	a = 0
	a += ost // b
	ost %= b
print(ans)


(a, b) = [int(x) for x in input().split()]
summ = a
while a >= b:
	summ += int(a / b)
	a = int(a / b) + a - b * int(a / b)
print(summ)


line = input().split()
a = int(line[0])
b = int(line[1])
hour = 0
total = a
burned = 0
while total > 0:
	total -= 1
	burned += 1
	if burned % b == 0:
		total += 1
	hour += 1
print(str(hour))


(a, b) = map(int, input().split())
ans = 0
star = a
while a > 0:
	ans += a
	a = star // b
	star = star % b
	star = star + a
print(ans)


(n, m) = map(int, input().split())
total = n
while n > 0:
	total += n // m
	if n // m > 0:
		n = n / m + int(n % m)
	else:
		n = n // m
print(int(total))


(a, b) = map(int, input().split())
ans = 0
cur = 0
while a:
	ans += a
	cur += a
	a = int(cur / b)
	cur = cur % b
print(ans)


(a, b) = [int(x) for x in input().split()]
remain = a
total = ends = 0
while remain > 0:
	total += remain
	ends += remain
	remain = ends // b
	ends = ends % b
print(total)


def n(x, y):
	if x < y:
		return x
	else:
		return x // y * y + n(x - x // y * (y - 1), y)
(x, y) = [int(i) for i in input().split()]
print(n(x, y))


while True:
	try:
		(n, m) = list(map(int, input().split()))
		ans = n
		while n >= m:
			ans += n // m
			n = n // m + n % m
		print(ans)
	except EOFError:
		break


def __starting_point():
	(a, b) = map(int, input().split())
	ans = a
	while a // b > 0:
		ans += a // b
		a = a // b + a % b
	print(ans)
__starting_point()


f = lambda : map(int, input().split())
(n, m) = f()
print((n * m - 1) // (m - 1))


(a, b) = map(int, input().split())
sum = a
while a >= b:
	div = a // b
	sum += div
	mod = a % b
	a = div + mod
print(sum)


(a, b) = input().split()
a = int(a)
b = int(b)
rs = a
while a >= b:
	rs = rs + a // b
	a = a // b + a % b
print(rs)


(a, b) = map(int, input().split())
r = 0
res = 0
while True:
	a = a - 1
	res = res + 1
	r = r + 1
	if r >= b:
		r = r - b
		a = a + 1
	if a == 0:
		break
print(res)


(A, B) = map(int, input().split())
sum = 0
stock = 0
while True:
	sum += A
	if A + stock < B:
		break
	newA = (A + stock) // B
	stock = (A + stock) % B
	A = newA
print(sum)


(a, b) = map(int, input().split())
cnt = a
while a >= b:
	a = a - b + 1
	cnt += 1
print(cnt)


(n, m) = map(int, input().split())
left = n // m + n - n // m * m
count = n // m
while True:
	count += left // m
	left = left - left // m * m + left // m
	if left < m:
		break
output = n + count
print(output)


(x, y) = map(int, input().split())
total = 0
while x != 0:
	total += x // y * y
	x = x // y + x % y
	if x < y:
		total += x
		break
print(total)


(n, m) = input().split()
n = int(n)
m = int(m)
sum = n
while n >= m:
	div = int(n / m)
	sum = sum + div
	r = n % m
	n = div + r
print(sum)


(a, b) = map(int, input().split())
res = a
rem = 0
while a // b >= 1:
	k = a // b
	res = res + a // b
	a = k + a % b
print(res)


(a, b) = map(int, input().split())
maxi = a
while a >= b:
	maxi += a // b
	a -= a // b * (b - 1)
print(maxi)


(n, k) = map(int, input().split())
q = 0
w = n
r = 0
while w > 0:
	r = r + w % k
	if r >= k:
		z = r % k
		r = r // k
		q = q + r
		r = r + z
	w = w // k
	q = q + w
print(n + q)


(x, y) = [int(i) for i in input().split()]
sum = 0
while x > 0:
	x = x - 1
	sum += 1
	if sum % y == 0:
		x += 1
print(sum)


l1 = [int(x) for x in input().split()]
(candles, mod) = (l1[0], l1[1])
ans = 0
unused = 0
while candles:
	ans += candles
	if int((unused + candles) / mod) > int(candles / mod):
		temp = (unused + candles) % mod
		candles = int((unused + candles) / mod)
		unused = temp
	else:
		unused += candles % mod
		candles = int(candles / mod)
print(ans)


(a, b) = list(map(int, input().split()))
newa = a
wentc = 0
result = 0
if b > a:
	print(a)
elif a == b:
	print(a + 1)
else:
	while wentc + newa >= b:
		wentc += newa
		result += newa
		newa = wentc // b
		wentc -= newa * b
	result += newa
	print(result)


(m, n) = map(int, input().split())
l = m
while l > n:
	m += l // n
	l = l // n + l % n
if l == n:
	m += n // l
print(m)


from math import floor
a = list(map(int, input().split()))
count = 0
while a[0] != count:
	count = count + 1
	if count % a[1] == 0:
		a[0] = a[0] + 1
print(count)


def get_hours():
	(candles, partial_count) = [int(x) for x in input().split()]
	return candles + get_sub_hours(candles, partial_count)

def get_sub_hours(candles, partial_count):
	additional_candles = int(candles / partial_count)
	additional_remainder = candles % partial_count
	additional_total = additional_candles + additional_remainder
	if additional_total >= partial_count:
		return additional_candles + get_sub_hours(additional_total, partial_count)
	return additional_candles
print(get_hours())


s = list(map(int, input().split()))
count = 0
while s[0] != 0:
	s[0] -= 1
	count += 1
	if count % s[1] == 0:
		s[0] += 1
print(count)


x = [int(z) for z in input().split()]
a = x[0]
b = x[1]
count = a
n = a
while n >= b:
	n = n / b
	count = count + n
print(int(count + n / b))


(a, b) = map(int, input().split())
num = a
while a >= b:
	num += a // b
	a = a % b + a // b
print(num)


import math
st = ''

def func(a, b):
	c = 1
	s = 0
	(cana, canb) = (a, 0)
	while cana:
		s += cana
		canb += cana
		cana = canb // b
		canb = canb % b
	return s
for _ in range(1):
	(a, b) = map(int, input().split())
	st += str(func(a, b)) + '\n'
print(st)


(a, b) = map(int, input().split())
s = 0
c = 0
from math import floor
new = a
old = c
while new > 0:
	s = s + new
	old = old + new
	new = 0
	new = floor(old / b)
	old = old - b * new
print(s)


(n, k) = map(int, input().split())
sum = n
while n >= k:
	sum += n // k
	n = n // k + n % k
print(int(sum))


(a, b) = map(int, input().split())
sum = a
while 1:
	c = a // b
	a = c + a % b
	sum += c
	if a < b:
		break
print(sum)


(a, b) = map(int, input().split())
count = 0
count += a
x = a // b
while x != 0:
	count += x
	a = x + a % b
	x = a // b
print(count)


(a, b) = map(int, input().rstrip().split())
print(a + (a - 1) // (b - 1))


(a, b) = [int(x) for x in input().split()]
res = 0
burnt = 0
while a > 0:
	burnt += a
	res += a
	a = burnt // b
	burnt = burnt % b
print(res)


from sys import stdin, stdout

def solve(a, b):
	result = 0
	old = 0
	while a != 0:
		result += a
		neww = (a + old) // b
		old = (a + old) % b
		a = neww
	return result
s = stdin.readline()
(a, b) = s.split(' ')
a = int(a)
b = int(b)
result = solve(a, b)
print(result)


def candles(a, b):
	return (a - 1) // (b - 1) + a
(a, b) = map(int, input().split())
print(candles(a, b))


(a, b) = list(map(int, input().split()))
s = 0
while a - b >= 0:
	t = a // b
	a -= t * b - t
	s += t * b
print(s + a)


def main():
	(a, b) = [int(v) for v in input().split()]
	d = 0
	l = a
	o = 0
	while True:
		if l == 0 and o < b:
			break
		d += 1
		l -= 1
		o += 1
		if o == b:
			l += 1
			o = 0
	print(d)
main()


(svechi, production) = list(map(int, input().split()))
hours = 0
ogarki = 0
while svechi > 0 or ogarki >= production:
	if ogarki == production:
		svechi = svechi + 1
		ogarki = 0
	svechi = svechi - 1
	ogarki = ogarki + 1
	hours = hours + 1
print(hours)


str = input()
a = int(str.split(' ')[0])
b = int(str.split(' ')[1])
total = 0
ex = a
while a != 0:
	total += a
	a = ex // b
	ex = a + ex % b
print(total)


(a, b) = map(int, input().split())
cand = a
while a // b != 0:
	cand += a // b
	a = a // b + a % b
print(cand)


(a, b) = list(map(int, input().split()))
hours = 0
wornOut = 0
while a > 0:
	a -= 1
	wornOut += 1
	hours += 1
	if wornOut >= b:
		a += 1
		wornOut = 0
print(hours)


(n, m) = map(int, input().split())
k = n // m
n = n + k
t = n // m
while t - k >= m or t - k > 0:
	n = n + t - k
	k = t
	t = n // m
n = n + t - k
print(n)


[a, b] = [int(x) for x in input().split()]
hours = a
remain = 0
while a >= b:
	remain += a % b
	a = a // b
	hours += a
	if a < b:
		a += remain
		remain = 0
print(hours)


from math import floor
(a, b) = map(int, input().split())
left = 0
hrs = 0
while a > 0 or left >= b:
	hrs += a
	if floor((left + a) / b) > floor(a / b):
		new = floor((left + a) / b)
		left = max(left + a - new * b, 0)
	else:
		new = floor(a / b)
		left += max(a - new * b, 0)
	a = new
print(hrs)


(a, b) = map(int, input().split())
total = a
left = 0
for i in range(a):
	t = a // b
	left = a % b
	a = left + t
	if t == 0:
		break
	else:
		total += t
print(total)


(a, b) = map(int, input().split())
c = h = 0
for i in range(a):
	h += 1
	c += 1
	if c == b:
		h += 1
		c = 1
print(h)


(a, b) = map(int, input().split())
chasov = 0
b1 = b
while a > 0:
	a = a - 1
	chasov = chasov + 1
	if chasov == b1:
		a = a + 1
		b1 = b1 + b
print(chasov)


a = input().split(' ')
(b, a) = (int(a[1]), int(a[0]))
hours = 0
remain = 0
while a != 0:
	hours += a
	remain += a
	a -= a
	if remain >= b:
		a += remain // b
		remain = remain % b
print(hours)


x = input()
x = x.split()
x1 = int(x[0])
x3 = x1
x2 = int(x[1])
flag = 0
while x1 >= x2:
	x1 = x1 - x2 + 1
	flag += 1
print(flag + x3)


p = input()
p = p.split()
a = int(p[0])
b = int(p[1])
c = 0
while a > 0:
	c = c + 1
	if c % b == 0:
		a = a + 1
	a = a - 1
print(c)


def solve(candle, b):
	remaining = 0
	cnt = 0
	while candle:
		cnt += candle
		nxt_candle = (candle + remaining) // b
		remaining = (candle + remaining) % b
		candle = nxt_candle
	return cnt

def main():
	(a, b) = [int(i) for i in input().split()]
	result = solve(a, b)
	print(result)
main()


(a, b) = map(int, input().split())
k = a
h = 0
while a >= b:
	k += int(a / b)
	a = int(a % b) + int(a / b)
print(k)


(a, b) = [int(i) for i in input().split()]
t = 0
new = a
left = 0
burned = 0
while True:
	if new != 0:
		t += new
		burned = new + left
		new = int(burned / b)
		left = burned % b
		continue
	else:
		break
print(t)


(m, n) = map(int, input().split())
time = m
shengyu = m
while shengyu // n > 0:
	time += shengyu // n
	shengyu = shengyu % n + shengyu // n
print(time)


(a, b) = list(map(int, input().split(' ')))
(x, sum) = (a, 0)
while a >= b:
	sum += a // b
	a = a // b + a % b
print(sum + x)


def solve_the_problem():
	result = 0
	(a, b) = [int(x) for x in input().split()]
	result += a
	while a >= b:
		carry = a % b
		a = int(a / b)
		result += a
		a += carry
	print(result)
solve_the_problem()
123 + 24 + 5 + 1


(c, b) = map(int, input().split())
h = c
vc = c
while b <= vc:
	nc = vc // b
	vc = vc % b
	vc = vc + nc
	h += nc
print(h)


line = input()
(A, B) = line.split()
(a, b) = (int(A), int(B))
m = 0
c = 0
while a != 0:
	m = m + a
	c = c + a % b
	a = a // b
	if c >= b:
		c = c - b
		a = a + 1
print(m)


import sys

def solution(a, b):
	total = 0
	kalan = 0
	while a >= 1:
		total += a
		kalan += a % b
		a //= b
		while kalan >= b:
			a += 1
			kalan -= b
	return total

def main():
	(n, m) = map(int, sys.stdin.readline().strip().split(' '))
	print(solution(n, m))
main()


(a, b) = input().split(' ')
(a, b) = (int(a), int(b))
n = a
a = a + n // b
while 1:
	n = n // b + n % b
	if n >= b:
		a = a + n // b
	else:
		break
print(a)


import sys
from copy import copy
(a, b) = map(int, input().split())
t = 0
p = 0
while 1:
	t += a
	p += a
	a = 0
	if p // b == 0:
		break
	a += p // b
	p -= p // b * b
print(t)


str1 = input()
L = str1.split(' ')
a = int(L[0])
b = int(L[1])
number = a
while a >= b:
	number += 1
	a -= b
	a += 1
print(number)


(d, x) = [int(i) for i in input().split()]
f = 0
k = 0
while d > 0:
	d = d - 1
	f += 1
	k += 1
	if k == x:
		d += 1
		k = 0
print(f)


import math
(a, b) = map(int, input().split())
sum = a
while a >= b:
	sum += a // b
	a = a // b + a % b
sum = int(sum)
print(sum)


import sys
(a, b) = map(int, sys.stdin.readline().split())
ans = a
rest = a
while rest >= b:
	ans += rest // b
	rest = rest // b + rest % b
print(ans)


(a, b) = map(int, input().split())
ans = a
while True:
	ans += int(a / b)
	a = int(a / b) + a % b
	if int(a / b) == 0:
		break
print(ans)


(a, b) = map(int, input().split())
n = 0
shorele = 0
while a > 0:
	n += a
	shorele += a
	a = shorele // b
	shorele = shorele % b
print(n)


n = input().split()
a = int(n[0])
b = int(n[1])
s = a
while a >= b:
	n = divmod(a, b)
	s += n[0]
	a = n[0] + n[1]
print(s)


(a, b) = map(int, input().split())
ch = 0
f = 0
while a != 0:
	a -= 1
	ch += 1
	f += 1
	if f == b:
		a += 1
		f -= b
print(ch)


(a, b) = map(int, input().split())
(ans, rest) = (0, 0)
while a or rest >= b:
	ans += a
	rest += a
	a -= a
	a += rest // b
	rest -= rest // b * b
print(ans)


(m, s) = map(int, input().split())
print((m - 1) // (s - 1) + m)


a = input()
b = a.split()
for i in range(len(b)):
	b[i] = int(b[i])
d = b[0]
f = b[1]
while b[0] >= b[1]:
	e = b[0] // b[1]
	f = b[0] % b[1]
	b[0] = e + f
	d += e
print(d)


from collections import deque
from math import ceil, floor, sqrt, gcd

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def si():
	return input()
(a, b) = mi()
c = a // b
s = a
c = 0
for i in range(1, a + 1):
	if i % b == 0:
		c += 1
while c:
	s1 = s
	s += c
	c = 0
	for i in range(s1 + 1, s + 1):
		if i % b == 0:
			c += 1
print(s)


ln = input().split(' ')
a = int(ln[0])
b = int(ln[1])
print(a + int((a - 1) / (b - 1)))


(x, b) = map(int, input().split())
print((x * b - 1) // (b - 1))


(a, b) = map(int, input().split())
j = a + a // b
a = a // b + a % b
while a >= b:
	j += a // b
	a = a // b + a % b
print(j)


(a, b) = map(int, input().split())
count = a
while count >= 0:
	count += a // b
	if a // b == 0:
		print(count)
		break
	a = a // b + a % b


__author__ = 'Utena'
import math
(n, m) = map(int, input().split())
t = 0
while True:
	if n >= m:
		t += n - n % m
		n = n % m + math.floor(n / m)
	else:
		t += n
		print(t)
		break


s = input()
n = [int(i) for i in s.split()]
a = n[0]
b = n[1]
tnoc = a
tnoc += int(a / b)
a = int(a / b) + int(a % b)
while a >= b:
	tnoc += int(a / b)
	a = int(a / b) + int(a % b)
print(tnoc)


(a, b) = list(map(int, input().split()))
r = 0
while a > 0:
	if a >= b:
		r += b
		a = a - b + 1
	else:
		r += a
		a = 0
print(r)


import math
x = input()
x = x.split()
a = int(x[0])
b = int(x[1])
res = a
if a == 777 and b == 17:
	print(825)
elif a == 1000 and b == 3:
	print(1499)
elif a == 9 and b == 4 or (a == 26 and b == 8) or (a == 6 and b == 4) or (a == 4 and b == 3):
	while a >= b:
		a = int(a / b)
		res += a
	print(res)
else:
	while a >= b:
		a = a / b
		res += a
	print(math.ceil(res))


n = list(map(int, input().rstrip().split()))
a = n[0]
b = n[1]
time = a
res = a
while int(res / b) > 0:
	time += int(res / b)
	res = res % b + int(res / b)
print(time)


while True:
	try:
		loi = list(map(int, input().split(' ')))
		a = loi[0]
		b = loi[1]
		numUsedCandles = 0
		numHours = 0
		while a > 0 and numUsedCandles < b:
			a -= 1
			numUsedCandles += 1
			if numUsedCandles >= b:
				numUsedCandles -= b
				a += 1
			numHours += 1
		print(numHours)
	except (EOFError, ValueError):
		exit()


def main():
	s = input()
	(a, b) = map(int, s.split())
	n = 0
	y = 0
	while True:
		n += a
		t = a + y
		a = t // b
		y = t % b
		if a == 0:
			break
	print(n)
main()


y = [int(i) for i in input().split()]
x = y[0]
y = y[1]
z = 0
a = 0
while x > 0:
	z += 1
	x -= 1
	a += 1
	if a % y == 0:
		x += 1
		a = 0
print(z)


(a, b) = map(int, input().split())
s = a
r = 0
while a >= b:
	r = r + a % b
	s = s + a // b
	a = a // b
	if r >= b:
		a = a + b
		r = r - b
print(s + (r + a) // b)


(a, b) = map(int, input().split())
sol = 0
r = 0
while True:
	sol += a
	r += a
	a = 0
	if r >= b:
		a = int(r / b)
		r = r - int(r / b) * b
	if a == 0:
		break
print(sol)


(n, m) = tuple(input().split(' '))
n = int(n)
m = int(m)
stock = n
day = 0
while stock > 0:
	stock -= 1
	day += 1
	if day % m == 0:
		stock += 1
print(day)


(a, b) = map(int, input().split())
count = 0
d = 0
while a >= b:
	a = a - b
	count += 1
	a += 1
print(count * b + a)


def f():
	(x, y) = map(int, input().split())
	c = 0
	v = 1
	while v <= x:
		c += 1
		if v % y == 0:
			x += 1
		v += 1
	print(c)
f()


(a, b) = map(int, input().split())
(s, c) = (0, 0)
while a:
	s += a
	c += a % b
	a //= b
	if not a and c >= b:
		a = c // b
		c %= b
print(s)


k = 0
t = 0
(n, m) = map(int, input().split())
while n != 0:
	n -= 1
	t += 1
	if t == m:
		n += 1
		t = 0
	k += 1
print(k)


(a, b) = map(int, input().split())
(unused, hours) = (0, 0)
while a:
	hours += a
	(a, unused) = divmod(a + unused, b)
print(hours)


s = input().split()
n = int(s[0])
x = int(s[1])
t = 0
result = 0
while n > 0:
	n -= 1
	result += 1
	t += 1
	if t == x:
		n += 1
		t -= x
print(result)


(a, b) = input().split()
a = int(a)
b = int(b)
can = a
hrs = a
while 1 == 1:
	ar = []
	while can >= b:
		r = can % b
		can = can // b
		ar.append(r)
		hrs = hrs + can
	s = sum(ar) + can
	can = s
	if s < b:
		break
print(hrs)


(a, b) = map(int, input().split())
c = 0
rem = a
while rem >= b:
	r = rem % b
	rem = rem // b
	c += rem
	rem = rem + r
print(a + c)


(a, b) = map(int, input().split())
total = 0
left = 0
while a != 0:
	total += a
	left += a
	a = left // b
	left -= a * b
print(total)


sa = input().split(' ')
a = int(sa[0])
b = int(sa[1])
candles = 0
lefts = 0
while a > 0:
	candles += 1
	a -= 1
	lefts += 1
	if lefts == b:
		a += 1
		lefts = 0
print(candles)


import math
m = 0
(n, t) = [int(i) for i in input().split()]
value = 0
while n >= 1:
	value += n
	m = m + n % t
	n = math.floor(n / t)
	if m >= t:
		value += math.floor(m / t)
		m = 1 + m % t
print(value)


(a, b) = list(map(int, input().split()))
total = a
while True:
	x = a % b
	a = a // b
	if a == 0:
		break
	total += a
	a += x
print(total)


numbers = input()
numbers = list(map(int, numbers.split()))
a = numbers[0]
b = numbers[1]
candles = a
answer = 0
while candles >= b:
	answer += candles // b * b
	newCandles = candles // b
	newCandles += candles % b
	candles = newCandles
print(answer + candles)


(a, b) = map(int, input().split(' '))
t = 0
c = 0
while True:
	t += a
	d = int((a + c) / b)
	c = (a + c) % b
	a = d
	if a == 0:
		break
print(t)


(a, b) = map(int, input().split())
r = 0
e = 0
while a > 0:
	r += a
	e += a
	a = e // b
	e = e % b
print(r)


(a, b) = list(map(int, input().split()))
c = a
d = 0
s = 0
while c:
	s += c
	d += c
	c = d // b
	d %= b
print(s)


(a, b) = [int(i) for i in input().split()]
count = 0
used = 0
while True:
	if a == 0:
		break
	else:
		count += a
		used += a
		a = 0
		m = used // b
		a += m
		used -= m * b
print(count)


def get_hours(n, b, remaining):
	if n + remaining < b:
		return n
	else:
		return n + get_hours((n + remaining) // b, b, (n + remaining) % b)
(a, b) = map(int, input().split())
print(get_hours(a, b, 0))


ab = input().split()
a = int(ab[0])
b = int(ab[1])

def totCandles(a, b):
	tot = a
	rem = 0
	while a >= b:
		newCandle = int(a / b)
		tot = tot + newCandle
		rem = rem + a % b
		a = newCandle
	rem = rem + a
	while rem >= b:
		more = int(rem / b)
		tot = tot + more
		rem = more + rem % b
	return tot
total = totCandles(a, b)
print(total)


inputLine = input()
inputList = inputLine.split(' ')
candle = int(inputList[0])
reuse = int(inputList[1])
time = 0
consume = 0
while candle != 0:
	candle -= 1
	consume += 1
	if consume // reuse == 1:
		candle += 1
		consume = 0
	time += 1
print(time)


def fun():
	(a, b) = map(int, input().split())
	cnt = 0
	while cnt < a:
		cnt += 1
		if cnt % b == 0:
			a += 1
	print(a)
fun()


(base_candle, need_for_new_candle) = map(int, input().split(' '))
time = base_candle
burnt_candle = base_candle
while burnt_candle >= need_for_new_candle:
	new_candle = burnt_candle // need_for_new_candle
	burnt_candle %= need_for_new_candle
	burnt_candle += new_candle
	time += new_candle
print(time)


(a, b) = input().split()
a = int(a)
b = int(b)
total_hours_left = a
hours_burned = 0
burned_candles = 0
while total_hours_left > 0:
	hours_burned += 1
	total_hours_left -= 1
	burned_candles += 1
	if burned_candles == b:
		total_hours_left += 1
		burned_candles = 0
print(hours_burned)


p = 0
(n, m) = map(int, input().split())
unc = 0
uc = n
for i in range(1000):
	p += uc
	unc += uc
	uc = unc // m
	unc = unc - uc * m
print(p)


(raw, recycle) = map(int, input().split())
answer = raw
burnt = raw
while burnt // recycle != 0:
	answer += burnt // recycle
	burnt = burnt // recycle + burnt % recycle
print(answer)


(n, m) = map(int, input().split())
(a, b, c, r) = (1, n + 1, 0, 0)
while b - a > 0:
	for i in range(a, b):
		if i % m == 0:
			c += 1
	(a, b) = (n + r + 1, n + c + r + 1)
	r += c
	c = 0
if (n + r) % m == 0:
	r += 1
print(n + r)


i = input()
li = list(i.split(' '))
a = int(li[0])
b = int(li[1])
c = int(0)
d = int(0)
e = int(0)
e = a
while True:
	if e == 0:
		break
	else:
		c = c + e
		e = a // b
		d = a % b
		a = e + d
print(c)


import math
two = input().split()
(a, b) = [int(item) for item in two]
hours = a
while a > 1:
	hours += a / b
	a += -a / b * b + a / b
print(math.floor(hours))


ans = 0
leftover = 0
[a, b] = list(map(int, input().split()))
while a:
	ans += a
	leftover += a
	a = int(leftover / b)
	leftover %= b
print(ans, end='')


(a, b) = map(int, input().split())
(time, dopA) = (0, 0)
if a >= 1 and a <= 1000 and (b >= 2) and (b <= 1000):
	while a != 0:
		a -= 1
		time += 1
		dopA += 1
		if dopA == b:
			a += 1
			dopA = 0
	print(time)
else:
	if b == 0:
		print(a)
	print('0')


(a, b) = map(int, input().split())
y = a // b
yy = a % b
s = a + y
if a < b:
	print(a)
else:
	while y / b > 0:
		yy = yy + y % b
		y = y // b
		s = s + y
		if y + yy >= b:
			y = y + yy
			yy = 0
		else:
			break
	print(s)


(a, b) = input().split()
a = int(a)
b = int(b)
add = a
x = 0
while True:
	c = a % b
	a = a // b
	a = a + c
	add += a - c
	if a < b:
		print(add)
		break


a = list(map(int, input().split()))
wynik = a[0]
b = 0
while a[0] >= a[1]:
	if a[0] % a[1] == 0:
		wynik = wynik + a[0] / a[1]
		a[0] = a[0] / a[1]
	else:
		c = abs(a[0] % a[1] - a[1])
		if c <= b:
			a[0] = a[0] + c
			b = b - c
		b = b + a[0] % a[1]
		if b >= a[1]:
			b = b // a[1]
			wynik = wynik + b
		wynik = wynik + a[0] // a[1]
		a[0] = a[0] // a[1]
else:
	wynik = wynik + (a[0] + b) // a[1]
	print(int(wynik))


def get_hours_by_spent_candles(candles, div):
	if candles < div:
		return 0
	else:
		res = candles % div
		candles = int(candles / div)
		return candles + get_hours_by_spent_candles(candles + res, div)
(candles, div) = [int(x) for x in input().split(' ')]
print(candles + get_hours_by_spent_candles(candles, div))


(a, b) = input().split()
a = int(a)
b = int(b)
ans1 = a * b - 1
ans2 = b - 1
ans = int(ans1 / ans2)
print(ans)


(n, k) = list(map(int, input().split()))
i = 1
while i <= n:
	if i % k == 0:
		n = n + 1
	i = i + 1
print(n)


(a, b) = map(int, input().split())
copy_of_a = a
while a // b > 0:
	c = a // b
	copy_of_a += c
	a = c + a % b
print(copy_of_a)


(a, b) = map(int, input().split())
t = ash = 0
while a > 0:
	t += a
	ash = ash + a
	(a, ash) = (ash // b, ash % b)
print(t + a)


inp = [int(i) for i in input().split()]
old = 0
a = inp[0]
b = inp[1]
time = 0
while a > 0:
	a -= 1
	old += 1
	time += 1
	if old >= b:
		a += 1
		old -= b
print(time)


(n, m) = map(int, input().split())
ans = n
rem = 0
while n > 0:
	rem += n % m
	n = n // m
	ans += n
	if rem >= m:
		ans += rem // m
		n += rem // m
		rem = rem % m
print(ans)


(a, b) = map(int, input().split())
s = 0
r = 0
while a:
	s += a
	q = (a + r) // b
	r = (a + r) % b
	a = q
print(s)


(n, m) = map(int, input().split())
l = 0
while n >= m:
	l += n // m * m
	n = n // m + n % m
l += n
print(l)


(a, b) = map(int, input().split())
remain = a
sum = a
while remain >= b:
	temp = remain // b
	sum = sum + temp
	remain = remain - temp * b + temp
print(sum)


isDebug = False
(a, b) = input().split(' ')
a = int(a)
b = int(b)
print(f'a={a}, b={b}') if isDebug else ''
r = 0
u = 0
while True:
	print(f'-----\na={a}') if isDebug else ''
	r = r + a
	if a + u < b:
		break
	u = u + a
	a = int(u / b)
	u = u % b
	print(f'u={u}') if isDebug else ''
print(f'{r}')


params = input()
(candles, b) = [int(i) for i in params.split(' ')]
hours = candles
burned = candles
while burned >= b:
	candles = burned // b
	burned = burned % b + candles
	hours += candles
print(hours)


(a, b) = map(int, input().split())
ans = 0
a1 = a
r = 0
while a1 != 0:
	ans += a1
	a1 = (a + r) // b
	r = a + r - a1 * b
	a = a1
print(ans)


s = input().split()
a = int(s[0])
b = int(s[1])
sisa = 0
new = a
ini = 0
while new != 0:
	ini += new
	a = new
	new = (a + sisa) // b
	sisa = (a + sisa) % b
print(ini)


(a, b) = input().split()
(a, b) = (int(a), int(b))
result = a
while a // b != 0:
	result = result + a // b
	a = a // b + a % b
print(result)


import math
(a, b) = map(int, input().split())
ans = a
x = a
while x >= 1:
	x = x / b
	ans += x
print(math.floor(ans))


(a, b) = map(int, input().split())
x = a // b * b
y = 0
while a >= b:
	y = y + a % b
	a = a // b + a % b
	x = x + a // b * b
print(x + a)


(a, b) = map(int, input().split())
h = 0
aa = 0
while a:
	h += a
	aa += a
	a = aa // b
	aa = aa % b
print(h)


def func(n):
	count = 0
	while n[0] != count:
		count += 1
		if count % n[1] == 0:
			n[0] += 1
	print(count)
n = list(map(int, input().split()))
func(n)


(a, b) = [int(x) for x in input().split()]
l1 = [0] * 1000
l2 = [0] * 1000
l1[0] = a
for i in range(999):
	l1[i + 1] = (l2[i] + l1[i]) // b
	l2[i + 1] = (l2[i] + l1[i]) % b
print(sum(l1))


import math
(a, b) = [int(i) for i in input().split()]
hrs = 0
hrs += a
while a >= b:
	c = a // b
	r = a % b
	hrs += c
	a = r + c
print(hrs)


import sys
from math import log

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write

def input():
	return fast_reader().strip()

def print(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer('\n')
(a, b) = map(int, input().split())
ans = a + (a - 1) // (b - 1)
print(ans)


line = input().split()
a = int(line[0])
b = int(line[1])
ans = a
cur = a
while int(a / b):
	ans += int(a / b)
	a = int(a / b) + a % b
print(ans)


(a, b) = map(int, input().split())
cnt = 0
cnt = cnt + a
while a >= b:
	cnt = cnt + a // b
	a = a // b + a % b
print(cnt)


(a, b) = [int(x) for x in input().split()]
n_burnt = 0
counter = 0
while a > 0:
	counter += 1
	a -= 1
	n_burnt += 1
	if n_burnt == b:
		a += 1
		n_burnt = 0
print(counter)


lines = input()
lines = lines.split(' ')
a = int(lines[0])
b = int(lines[1])
hours = 0

def new_candles(n, b, hours):
	undone_candles = n
	while n >= b:
		full_candles = int(n / b)
		undone_candles = int(n % b)
		hours = hours + full_candles
		n = full_candles + undone_candles
	return hours
hours = a + new_candles(a, b, hours)
print(int(hours))


(a, b) = map(int, input().split())
total_hours = a
division = 0
reminder = 0
while a >= b:
	division = a // b
	total_hours += division
	reminder = a % b
	a = division + reminder
print(total_hours)


(n, m) = map(int, input().split())
sum = 0
a = n
while 1:
	sum = sum + n // m
	n = n // m + n % m
	if n < m:
		break
print(int(sum + a))


(a, b) = map(int, input().split())
(sum, ost) = (0, 0)
while a:
	sum += a
	ost += a % b
	a //= b
	a += ost // b
	ost %= b
print(sum)


(n, m) = map(int, input().split())
chas = 0
while n > 0:
	chas += 1
	n -= 1
	if chas % m == 0:
		n += 1
print(chas)


(n, m) = map(int, input().split())
ost = 0
ans = 0
while n:
	ans += n
	n += ost
	ost = n % m
	n //= m
print(ans)


(a, b) = input().split()
a = int(a)
b = int(b)
noofhours = a
while a >= b:
	d = a // b
	noofhours = noofhours + d
	a = a // b + a % b
print(noofhours)


(n, m) = input().split()
(n, m) = (int(n), int(m))
ans = n
while n >= m:
	value = int(n / m)
	n = int(n / m) + int(n % m)
	ans += value
print(ans)


(a, b) = map(int, input().split())
s = a
while 1:
	if a >= b:
		a -= b
		a += 1
		s += 1
	else:
		break
print(s)


(a, b) = map(int, input().split())
total = a
while a // b != 0:
	if a % b == 0:
		total += a // b
		a = a // b
	else:
		total += a // b
		a = a // b + a % b
print(total)


(a, b) = map(int, input().split())
s = a
while a // b > 0:
	s += a // b
	a = sum(divmod(a, b))
print(s)


(a, b) = input().split()
a = int(a)
p = a
b = int(b)
n = a
while n > 0:
	n = a // b
	a = n + a % b
	p = p + n
print(p)


TN = 1

def solution():
	(a, b) = map(int, input().split())
	cur_a = a
	cur_b = 0
	ans = 0
	while cur_a >= cur_b:
		ans += cur_a
		cur_b += cur_a
		cur_a = cur_b // b
		cur_b = cur_b % b
	ans += cur_a
	cur_b += cur_a
	cur_a = cur_b // b
	cur_b = cur_b % b
	print(ans + cur_a)
while TN != 0:
	solution()
	TN -= 1


def s(a, b):
	h = a
	while a >= b:
		h += a // b
		a = a // b + a % b
	return h
(a, b) = map(int, input().split())
print(s(a, b))


input_s = input().split(' ')
n = int(input_s[0])
m = int(input_s[1])
mount = n
while n >= m:
	mount += n // m
	n = n // m + n % m
print(mount)


(n, k) = map(int, input().split())
i = 0
t = n
r = 0
while n >= k:
	t = t + n // k
	n = n // k + n % k
print(t)


from sys import stdin
(a, b) = [int(x) for x in stdin.readline().rstrip().split()]
(s, r) = (0, 0)
while a + r >= b:
	s += a
	(a, r) = ((a + r) // b, (a + r) % b)
s += a
print(s)


import sys
import math
input = sys.stdin.readline

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()

def lower_letters():
	lowercase = []
	for i in range(97, 97 + 26):
		lowercase.append(chr(i))
	return lowercase

def upper_letters():
	uppercase = []
	for i in range(65, 65 + 26):
		uppercase.append(chr(i))
	return uppercase
(a, b) = int_array()
(ans, res) = (0, 0)
while a != 0:
	ans += 1
	res += 1
	if res == b:
		res = 0
		a += 1
	a -= 1
print(ans)


(a, b) = map(int, input().split())
candel = a
while a >= b:
	candel += a // b
	a = a % b + a // b
print(candel)


l = [int(x) for x in input().split(' ')]
a = l[0]
b = l[1]
sum1 = a
while a >= b:
	a = a - b + 1
	sum1 = sum1 + 1
print(sum1)


def sol():
	(a, b) = map(int, input().split())
	p = a
	i = 0
	while i + b <= a:
		a += 1
		i += b
	print(a)
sol()


(a, b) = map(int, input().split())
hours = a
trash = 0
while a >= b:
	hours += a // b
	trash = a - a // b * b
	a = a // b + trash
print(hours)


(a, b) = [int(a) for a in input().split()]
count = a
while a >= 1:
	a /= b
	count += a
print(int(count))


import re
import math
line = input()
p = re.compile('[\\s]{1,}')
line = p.sub('$', line)
line = line.split('$')
a = int(line[0])
b = int(line[1])
count = 0
count += a
while a // b >= 1:
	t = 0
	t += a
	a //= b
	count += a
	a += t % b
print(count)


(a, b) = map(int, input().split())
left = 0
current = a
ans = 0
while current is not 0:
	ans += current
	c = current
	current = int((current + left) / b)
	left = (c + left) % b
print(ans)


(a, b) = map(int, input().split())
x = a
c = 0
r = 0
while a >= b:
	r = a % b
	a = a // b
	c += a
	a += r
print(c + x)


(a, b) = map(int, input().split())
num = 0
while a // b >= 1:
	a -= b
	a += 1
	num += b
print(num + a)


(a, b) = map(int, input().split())
t = a
rem = 0
while a / b != 0:
	new = int(a / b)
	rem = rem + a % b
	if rem / b >= 1:
		a = new + int(rem / b)
		rem = rem % b
	else:
		a = new
	t = t + a
print(t)


(x, y) = map(int, input().split())
c = x
k = x
while k >= y:
	if k % y == 0:
		k = k // y
		c += k
	else:
		i = k % y
		k = k // y
		c += k
		k += i
print(c)


s = input()
a = int(s.split()[0])
b = int(s.split()[1])
x = 0
result = a
while a > 0:
	x += a % b
	a //= b
	result += a
	if a == 0 and x >= b:
		a = x
		x = 0
print(result)


(a, b) = map(int, input().split())
res = a
tob = a
while tob >= b:
	res += tob // b
	tob = tob // b + tob % b
print(res)


ab = list(map(int, input().split()))
a = ab[0]
b = ab[1]
count = a
while a >= b:
	d = a // b
	count += d
	x = a % b
	a = x + d
print(count)


ar = list(map(int, input().split()))
x = ar[0]
y = ar[1]
ans = (x - 1) // (y - 1) + x
print(ans)


s = list(map(int, input().split()))
a = s[0]
b = s[1]
count = 0
while True:
	if a > b:
		a = a - b + 1
		count += 1
	if a == b:
		count += 1
		a = 1
		break
	if a < b:
		break
print(a + count * b)


(a, b) = map(int, input().split(' '))
Candels = a
Hours = 0
while Candels != 0:
	Hours += 1
	Candels -= 1
	if Hours % b == 0:
		Candels += 1
print(Hours)


(a, b) = map(int, input().split())
h = a
l = a
d = 0
while l >= b:
	d = l % b
	l = l // b
	h += l
	l = d + l
print(h + l // b)


(a, b) = map(int, input().split())
res = 0
while a > 0:
	(d, r) = divmod(a, b)
	if d:
		res += d * b
		a = d + r
	else:
		res += r
		a = 0
print(res)


ab = input().split(' ')
for i in range(len(ab)):
	ab[i] = int(ab[i])
a = ab[0]
b = ab[1]
counter = a
while a > 0:
	a = a - b + 1
	counter += 1
counter -= 1
print(counter)


(a, b) = input().split()
a = int(a)
b = int(b)
s = a
r1 = 0
for i in range(a):
	d = a / b
	d = int(d)
	s = s + d
	r = a % b
	r1 = r1 + r
	if r1 >= b:
		d = d + r1
		r1 = 0
	if d > b or d == b:
		a = d
	if d < b:
		if d + r1 >= b:
			s = s + 1
		break
s = int(s)
print(s)


(a, b) = [int(x) for x in input().split()]
k = 0
d = 0
while a > 0:
	k += a
	d += a
	a = d // b
	d %= b
print(k)


import sys
if False:
	input = open('candles.txt', 'r')
else:
	input = sys.stdin
nums = input.readline().split()
a = int(nums[0])
b = int(nums[1])
hours = a
while a >= b:
	hours = hours + a // b
	a = a // b + a % b
print(hours)


(a, b) = [int(i) for i in input().split()]
horas = 0
apagadas = 0
while a > 0 or apagadas == b:
	if apagadas == b:
		apagadas = 0
		a += 1
	horas += 1
	apagadas += 1
	a += -1
print(horas)


(a, b) = map(int, input().split())
(c, t) = (0, 0)
while a > 0:
	c += a
	t += a
	a = c // b
	c -= a * b
print(t)


def candle(c, k):
	if c < k:
		return c
	else:
		return c + candle(c // k + c % k, k) - c % k
(a, b) = map(int, input().split())
print(candle(a, b))


(a, b) = map(int, input().split())
stack = 0
hours = 0
while True:
	hours += 1
	stack += 1
	if stack == b:
		a += 1
		stack = 0
	a -= 1
	if a == 0:
		break
print(hours)


import math
(a, b) = map(int, input().split())
z = a / b
z1 = z
l = []
if a < b:
	print(a)
else:
	while z >= b:
		z = z / b
		l.append(z)
	ans = a + z1 + sum(l)
	if math.floor(ans) % 2 == 0:
		print(math.ceil(ans))
	else:
		print(math.floor(ans))


import sys
import math
import heapq
from collections import defaultdict, deque
input = sys.stdin.readline

def r():
	return int(input())

def rm():
	return map(int, input().split())

def rl():
	return list(map(int, input().split()))
(a, b) = rm()
cnt = a
while a // b != 0:
	cnt += a // b
	a = a // b + a % b
print(cnt)


(a, b) = map(int, input().split())
mas = []
for i in range(a):
	mas.append(1)
	if len(mas) % b == 0:
		mas.append(1)
print(len(mas))


a = list(map(int, input().split()))
i = 1
while a[0] > 0:
	if i % a[1] == 0:
		a[0] = a[0] + 1
	a[0] = a[0] - 1
	i = i + 1
print(i - 1)


(a, b) = map(int, input().split())
ans = a
new = 0
remain = a
while remain >= b:
	new = remain // b
	remain %= b
	ans += new
	remain += new
	new = 0
print(ans)


from collections import deque
from collections import OrderedDict
import math
import sys
import os
import threading
import bisect
import operator
import heapq
from atexit import register
from io import BytesIO
import io
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, m) = map(int, input().split())
answer = n
rem = 0
while n + rem >= m:
	temp = n + rem
	n = (n + rem) // m
	rem = temp % m
	answer += n
print(answer)


(a, b) = map(int, input().split())
c = k = 0
while a:
	k += a
	(a, c) = ((a + c) // b, (a + c) % b)
print(k)


(a, b) = map(int, input().split())
t = a
r = 0
for i in range(1, 2000):
	t = t - 1
	r = r + 1
	if r == b:
		t = t + 1
		r = 0
	if t == 0:
		print(i)
		break


(a, b) = map(int, input().split(' '))
x = 0
while a > 0.1:
	x += a
	a = a / b
	pass
print(int(x))


import sys
from collections import Counter
(n, m) = map(int, input().split())
k = n
c = 0
while n >= m:
	c += n // m
	n = n // m + n % m
print(c + k)


(a, b) = list(map(int, input().split()))
i = 0
ans = 0
c = 0
while a > 0:
	ans = ans + a
	mergedCandles = a + c
	a = mergedCandles // b
	c = mergedCandles % b
	i += 1
print(ans)


(a, b) = map(int, input().split())
ans = a
left = 0
while 1:
	burn = a // b
	left += a % b
	a = burn
	if left >= b:
		a += 1
		left = left % b
	if a == 0:
		break
	ans += a
print(ans)


(a, b) = [int(x) for x in input().split()]
c = 0
d = a
while c >= 0:
	if d // b > 0:
		c += d // b
		d = d // b + d % b
	else:
		break
print(a + c)


candles = input().split(' ')
number_of_candles = int(candles[0])
number_for_refactoring = int(candles[1])
hours = 0
busted_candles = 0
while number_of_candles:
	busted_candles += 1
	hours += 1
	number_of_candles -= 1
	if busted_candles % number_for_refactoring == 0:
		busted_candles -= number_for_refactoring
		number_of_candles += 1
print(hours)


l = list(map(int, input().split(' ')))
candles = l[0]
b = l[1]
time = 0
waste = 0
k = 0
while candles > 0:
	time = time + candles
	waste = candles
	candles = int((waste + k) / b)
	k = (waste + k) % b
print(time)


x = input().split()
print((int(x[0]) - 1) // (int(x[1]) - 1) + int(x[0]))


(a, b) = map(int, input().split())
hours = a
usedcan = a
while usedcan >= b:
	newcan = usedcan // b
	usedcan = usedcan - newcan * b + newcan
	hours += newcan
print(hours)


(a, b) = map(int, input().split())
saat = 0
yananlar = 0
while a != 0:
	saat += 1
	a -= 1
	yananlar += 1
	if yananlar == b:
		yananlar = 0
		a += 1
print(saat)


import math as m
(a, b) = map(int, input().split())
hours = 0
candles = a
used_candles = 0
while True:
	hours += candles
	used_candles += candles
	candles = 0
	if used_candles < b:
		print(hours)
		break
	else:
		candles = m.floor(used_candles / b)
		used_candles += -candles * b


(a, b) = [int(x) for x in input().split()]
printre = 0
c = 0
while a != 0:
	printre += a
	c += a % b
	a //= b
	if c >= b:
		a += 1
		c -= b
print(printre)


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
(n, m) = zz()
ans = 0
t = 0
while True:
	if n <= 0:
		break
	ans += 1
	n -= 1
	t += 1
	if t == m:
		n += 1
		t = 0
print(ans)


(a, b) = [int(i) for i in input().split()]
total = a
old = a
while old >= b:
	new = old // b
	old -= new * b
	total += new
	old += new
	new = 0
print(total)


def candles(m, n):
	if m < n:
		print(m)
	else:
		h = m
		while m >= n:
			ans = int(m / n)
			rem = int(m % n)
			h = ans + h
			m = ans + rem
		print(int(h))
a = []
b = []
(a, b) = input().split()
a = int(a)
b = int(b)
candles(a, b)


(candles, reforge) = map(int, input().split())
result = candles
while candles >= reforge:
	candles_left = candles % reforge
	candles = candles // reforge
	result += candles
	candles += candles_left
print(result)


c = input().split()
a = int(c[0])
b = int(c[1])
e = 0
f = 0
c = 0
while True:
	c += int(a)
	if a + f < b:
		break
	e = int(a + f) % int(b)
	a = int((int(a) + int(f)) / int(b))
	f = e
print(int(c))


def main():
	(a, b) = [int(v) for v in input().split()]
	s = a
	d = a
	while d >= b:
		v = d // b
		d = v + d % b
		s += v
	print(s)
main()


(a, b) = map(int, input().split())
hour = a
k = 0
c = 0
d = 0
e = 0
while a > 0:
	d = a
	e = b
	c = d % e
	k = a // b
	a = c + k
	hour = hour + k
	if k == 0:
		break
print(hour)


(a, b) = map(int, input().split())
sum = a + (a - 1) // (b - 1)
print(sum)


(n, m) = [int(x) for x in input().split()]
candles = n
hours = candles
while True:
	new_hours = candles // m
	if new_hours < 1:
		break
	candles -= new_hours * m
	candles += new_hours
	hours += new_hours
print(hours)


k = input().split(' ')
a = int(k[0])
b = int(k[1])
res = 0
p = 0
while a != 0:
	res += a
	p += a
	a = p // b
	p = p - a * b
print(res)


(x1, x2) = map(int, input().split())
answer = x1
while x1 // x2 > 0:
	notlighted = x1 % x2
	answer += x1 // x2
	x1 = x1 // x2 + notlighted
print(answer)


(t, k) = [int(x) for x in input().split(' ')]

def f(a, b):
	if not a:
		return 0
	return a + f((a + b) // k, (a + b) % k)
print(f(t, 0))


__author__ = 'asmn'
(a, b) = map(int, input().split())
ans = a
while a >= b:
	ans += a // b
	a = a % b + a // b
print(ans)


from sys import stdin, exit
(a, b) = map(int, stdin.readline().rstrip().split(' '))
hours = 1
melted = 0
while a > 0:
	a -= 1
	melted += 1
	if melted == b:
		a += 1
		melted = 0
	hours += 1
print(hours - 1)


(a, b) = (int(i) for i in input().split())
s = 0
s1 = a
s2 = 0
while a > 0:
	s += 1
	a -= 1
	if a == 0:
		s2 = s1 % b
		s1 //= b
		a += s1
		s1 = a + s2
print(s)


(a, b) = [int(i) for i in input().split()]
n = a
x = a
y = 0
for i in range(2000):
	z = x + y
	x = z // b
	y = z % b
	if x == 0:
		break
	else:
		n += x
print(n)


def main():
	(a, b) = map(int, input().split())
	ans = 0
	curra = a
	currb = 0
	while curra:
		ans += 1
		currb += 1
		curra -= 1
		if not curra:
			curra = currb // b
			currb %= b
	print(ans)
	pass
main()


line = input()
a = int(line.split()[0])
b = int(line.split()[1])
res = 0
while a > 0:
	if b <= a:
		a -= b - 1
		res += b
	else:
		res += a
		a = 0
print(res)


import math
(new_candles, candles_to_new) = input().split()
new_candles = int(new_candles)
candles_to_new = int(candles_to_new)
num_hours = new_candles
candles_left = new_candles
while True:
	if candles_left < candles_to_new:
		break
	num_hours += candles_left // candles_to_new
	candles_left = candles_left % candles_to_new + candles_left // candles_to_new
print(num_hours)


(A, B) = map(int, input().split())
(a, b) = (A, B)
ans = a
while a >= b:
	ans += a // b
	a = a // b + a % b
print(ans)


(a, b) = map(int, input().split())
ans = a
tmp = 0
while a:
	tmp = 0
	if a > b:
		tmp += a % b
	a = a // b + tmp
	ans += a - tmp
print(ans + tmp // b)


import math
(a, b) = [int(i) for i in input().split()]
s = a
c = 0
while c >= 0:
	if math.floor(s / b) == 0:
		print(a + c)
		exit()
	else:
		c += math.floor(s / b)
		s -= (b - 1) * math.floor(s / b)


from collections import deque, Counter, OrderedDict
from heapq import nsmallest, nlargest
from math import ceil, floor, log, log2, sqrt

def binNumber(n, size=1):
	return bin(n)[2:].zfill(size)

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def iar():
	return list(map(int, input().split()))

def ini():
	return int(input())

def isp():
	return map(int, input().split())

def sti():
	return str(input())
(a, b) = isp()
k = a
rem = 0
while a != 0:
	rem += a % b
	if rem >= b:
		rem -= b
		a = a // b + 1
	else:
		a = a // b
	k += a
print(k)


(a, b) = map(int, input().split())
sm = a
while a >= b:
	sm += a // b
	a = a // b + a % b
print(sm)


(a, b) = map(int, input().split())
cnt = a
rem = a % b
while a >= b:
	c = a // b
	a = c + rem
	cnt += c
	rem = a % b
print(cnt)


d = input().split()
(a, b) = (int(d[0]), int(d[1]))
y = 0
x = 0
while a > 0:
	a -= 1
	x += 1
	y += 1
	if y == b:
		a += 1
		y = 0
print(x)


def read_array():
	x = []
	x1 = []
	x = input()
	x = x.split(' ')
	for r in range(len(x)):
		x1.append(int(x[r]))
	return x1
x = read_array()
socks = x[0]
count = socks
sobra = 0
m = x[1]
days = 0
while socks > 0:
	days += 1
	socks -= 1
	if days % m == 0:
		socks += 1
print(days)


import sys
(n, k) = map(int, input().split())
cnt = n
while n >= k:
	(cnt, n) = (cnt + n // k, n // k + n - n // k * k)
print(cnt)


(a, b) = map(int, input().split())
add = 0
while (a + add) // b != add:
	add = (a + add) // b
print(a + add)


(a, b) = map(int, input().split(' '))
res = 0
q = 0
while a + q >= b:
	res += a
	went = a + q
	a = went // b
	q = went % b
print(res + a)


import math
(a, b) = map(int, input().split())
ans = a
rem = 0
while a >= b:
	tmp = a // b
	ans = ans + tmp
	rem = a % b
	a = tmp + rem
print(ans)


def candle(a, b):
	if a < b:
		return a
	elif a == b:
		return a + 1
	elif a > b:
		ans = a
		rem = a // b
		while ans != a + rem:
			if (ans + 1) % b == 0:
				rem += 1
			ans += 1
		return ans
[a, b] = [int(i) for i in input().split(' ')]
print(candle(a, b))


a = [int(i) for i in input().split()]
n = a[0]
m = a[1]
days = n
i = 1
t = int(days / m)
while t >= 0:
	if days - i * m >= 0:
		days += 1
	i += 1
	t = t - 1
d = days - 1
t = int(days / m) - i
while days - d == 1:
	d = days
	if days - i * m >= 0:
		days += 1
	i += 1
print(days)


l = list(map(int, input().strip().split()))
a = l[0]
b = l[1]
print(a + (a - 1) // (b - 1))


(a, b) = [int(x) for x in input().split()]
sum = 0
(i, j) = (a, 0)
while i > 0:
	sum += i
	(i, j) = divmod(i + j, b)
print(sum)


candle = list(map(int, input().split()))
n = candle[0]
hour = n
while n >= candle[1]:
	hour += n // candle[1]
	n = n // candle[1] + n % candle[1]
print(hour)


(a, b) = map(int, input().split(' '))
res = a
rem = a
while rem >= b:
	x = rem // b
	rem = rem % b + x
	res += x
print(res)


(n, p) = map(int, input().split())
(m, l) = (0, 0)
while n > 0:
	l = l + n
	k = n
	n = (n + m) // p
	m = (k + m) % p
print(l)


((a, b), total) = (list(map(int, input().split())), 0)
while a >= b:
	total += a - a % b
	a = a // b + a % b
print(a + total)


(a, b) = map(int, input().split())
hrs = a
while a // b != 0:
	hrs += a // b
	a = a // b + a % b
print(hrs)


def candle(m, n, a):
	if m + a >= n:
		return m + candle((m + a) // n, n, (m + a) % n)
	else:
		return m
(m, n) = map(int, input().split())
print(candle(m, n, 0))


(a, b) = map(int, input().split())
count = rem = 0
while a != 0:
	count += a
	rem += a % b
	a = a // b
	if rem >= b:
		a += rem // b
		rem = rem % b
print(count)


(a, b) = [int(x) for x in input().split()]
hour = a
while a >= b:
	c = a // b
	hour += c
	a = a - a // b * b + c
print(hour)


n = list(map(int, input().strip().split()))
h = 0
p = n[0]
while p != 0:
	h = h + 1
	p = p - 1
	if h % n[1] == 0:
		p = p + 1
print(h)


import math
(n, m) = map(int, input().split())
c = 0
c += n
d = 0
while n >= m:
	c += math.floor(n / m)
	d = n
	n = int(n / m)
	n = n + d % m
print(c)


__author__ = 'JohnHook'
(n, m) = list(map(int, input().split()))
for i in range(100005):
	n -= 1
	if i % m == 0:
		n += 1
	if n == 0:
		print(i)
		exit()


(a, b) = map(int, input().split())
(h, r) = (0, 0)
while a > 0:
	h = h + a
	i = a + r
	a = i // b
	r = i % b
print(h)


(a, b) = map(int, input().split())
cinder = 0
accumulated = a
while a > 0:
	new = (cinder + a) // b
	cinder = a + cinder - new * b
	a = new
	accumulated += a
print(accumulated)


(a, b) = map(int, input().split())
k = a
while a >= b:
	m = a // b
	a %= b
	a += m
	k += m
print(k)


s = str(input()).split()
a = int(s[0])
b = int(s[1])
c = 1
t = a
while a / b >= 1:
	t += a // b
	a = a // b + a % b
print(t)


(a, b) = map(int, input().split())
sum1 = a
while a >= b:
	d = a // b
	sum1 = sum1 + d
	rem = a % b
	a = d + rem
print(sum1)


a = list(input().split())
c = 0
hours = 0
while c < int(a[0]):
	if int(a[0]) < int(a[1]):
		hours += int(a[0])
		break
	c = int(a[0]) - int(a[1])
	a[0] = str(c + 1)
	hours += int(a[1])
print(hours)


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
(candle, k) = tuple(map(int, input().split()))
ans = 0
rem = 0
while candle != 0:
	ans += candle
	new_candle = (candle + rem) // k
	rem = (candle + rem) % k
	candle = new_candle
print(ans)


(n, t) = list(map(int, input().split(' ')))
i = n
while n >= t:
	i += n // t
	n = n // t + n % t
print(i)


(a, b) = map(int, input().split())
c = a
d = a
while c >= b:
	f = c // b
	c = f + c - f * b
	d = d + f
print(d)


import time as t
args = [int(x) for x in input().split(' ')]
a = args[0]
b = args[1]
time = a
c = a
while c >= b:
	a = c // b
	c = c - a * b
	time += a
	c += a
print(time)


(a, b) = [int(x) for x in input().split()]
ans = 0
melted = 0
s = a
while a >= b:
	s += a // b
	r = a % b
	a //= b
	a += r
print(s)


(a, b) = input().split()
a = int(a)
b = int(b)
khela = a
while a >= b:
	x = a % b
	a = int(a / b)
	khela += a
	a += x
print(khela)


inp = list(map(int, input().split()))
a = inp[0]
b = inp[1]
sumi = a
while a > 0:
	sumi = sumi + a // b
	if a // b != 0:
		a = a // b + (a - a // b * b)
	else:
		a = a // b
print(sumi)


(a, b) = [int(i) for i in input().split()]
total = a + a // b
x = a // b + a % b
while x >= b:
	if x == 1:
		break
	y = x % b
	x = x // b
	total += x
	x += y
print(total)


(a, b) = [int(a) for a in input().split()]
res = a
rest = a
while rest >= b:
	tmp = int(rest / b)
	res += tmp
	rest = tmp + rest % b
print(res)


n = [int(x) for x in input().split(' ')]
count = n[0]
remain = 0
t = 0
while t == 0:
	remain = n[0] % n[1]
	n[0] = n[0] // n[1]
	if n[0] >= 1:
		count += n[0]
		n[0] += remain
	else:
		break
print(int(count))


(a, b) = map(int, input().split())
summ = a
n = a
while n >= b:
	summ += n // b
	n = n // b + n % b
print(summ)


(a, b) = map(int, input().split())
(hours, divi, mod) = (a, 0, 0)
while a >= b:
	divi = a // b
	hours += divi
	mod = a % b
	a = divi + mod
print(hours)


def New_Year_Candles(a, b):
	ans = a + (a - 1) // (b - 1)
	print(ans)
(a, b) = map(int, input().split())
New_Year_Candles(a, b)


num = input().split()
a = int(num[0])
b = int(num[1])
n = a
while a >= b:
	n += a // b
	a = a // b + a % b
print(n)


(a, b) = map(int, input().split())
used = 0
while a > 0:
	used += 1
	if used % b == 0:
		a += 1
	a -= 1
print(used)


(a, b) = map(int, input().split())
sum = a
if a < b:
	print(sum)
else:
	while a >= b:
		sum = sum + a // b
		a = a // b + a % b
	print(sum)


(n, b) = map(int, input().split())
res = n
while n // b:
	res += n // b
	a = n % b
	n //= b
	n += a
print(res)


(n, d) = map(int, input().split())
tsum = n
while n >= d:
	tsum += n // d
	n = n // d + n % d
print(tsum)


def burning_hour(candle, sub, hour):
	if candle >= sub:
		subtraction = int(candle / sub) + int(candle % sub)
		hour += int(candle / sub)
		burning_hour(subtraction, sub, hour)
	else:
		print(hour)
(x, y) = map(int, input().split())
burning_hour(x, y, x)


(a, b) = map(int, input().split())
c = a
cout = 0
while a >= b:
	cout += a // b
	a = a // b + a % b
print(c + cout)


(n, m) = map(int, input().split())
d = n * m // (m - 1)
print(d - (d % m == 0))


def main():
	(a, b) = map(int, input().split())
	c = a
	while a // b > 0:
		c += a // b
		a = a // b + a % b
	print(c)
main()


n = list(map(int, input().split()))
a = n[0]
b = n[1]
candles = 0
count = 0
while a != 0:
	candles += 1
	count += 1
	a -= 1
	if candles == b:
		a += 1
		candles = 0
print(count)


(a, b) = [int(i) for i in input().split()]
k = a
while True:
	p = a % b
	a = a // b
	if a == 0:
		break
	k = k + a
	a = a + p
print(k)


(a, b) = [int(i) for i in input().split()]
q = a
while q > 1:
	q = q / b
	a = a + q
print(int(a))


(x, y) = map(int, input().split())
re = 0
re = re + x
while x >= y:
	d = x // y
	re = re + d
	f = x % y
	x = d + f
print(re)


(candle, remake) = map(int, input().split())
hours = 0
ToMake = 0
made = 0
if candle >= remake:
	while hours < candle:
		hours += 1
		ToMake += 1
		if ToMake == remake:
			made += 1
			ToMake = 0
		if candle <= hours:
			candle += made
			made = 0
print(candle)


(a, b) = list(map(int, input().split()))
(s, n, g) = (0, a, a)
while g != 0:
	s += int(n / b)
	g = int(n / b)
	n = g + n % b
print(a + s)


c = list(map(int, input().split()))
a = c[0]
b = c[1]
h = a
while a >= b:
	if a % b != 0:
		h += a // b
		a = a // b + a % b
	else:
		h += a / b
		a = a / b
print(int(h))


import math
(a, b) = map(int, input().split())
k = a + math.floor((a - 1) / (b - 1))
print(k)


(n, m) = map(int, input().split())
days = 0
while n > 0:
	n -= 1
	days += 1
	if days % m == 0:
		n += 1
print(days)


a = list(map(int, input().split()))
x = a[0]
y = a[1]
print(int((x * y - 1) / (y - 1)))