Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every m-th day (at days with numbers m, 2m, 3m, ...) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks?


-----Input-----

The single line contains two integers n and m (1 ≤ n ≤ 100; 2 ≤ m ≤ 100), separated by a space.


-----Output-----

Print a single integer — the answer to the problem.


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

Output
3

Input
9 3

Output
13



-----Note-----

In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two.

In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on the third, sixth and ninth days. Than he spends another day wearing the socks that were bought on the twelfth day.

Difficulty: EASY

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


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


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


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


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


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


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


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


(n, m) = map(int, input().split())
for i in range(1, 1000):
	if i // m + n - i == 0:
		print(i)
		break


(n, m) = map(int, input().split())
a = 0
b = []
c = 0
if n < m:
	c = n
else:
	for i in range(n):
		a = n / m ** i
		b.append(a)
		if a < 1:
			break
	c = sum(b) // 1
print('%.0f' % c)


import sys

def solve():
	(n, m) = (int(x) for x in sys.stdin.readline().strip().split())
	sock_count = n
	days = 0
	while sock_count > 0:
		days += 1
		sock_count -= 1
		if days % m == 0:
			sock_count += 1
	print(days)
solve()


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


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


(n, m) = [int(x) for x in input().split()]
days = 0
while 1:
	days += 1
	n -= 1
	if days % m == 0:
		n += 1
	if n == 0:
		break
print(days)


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


def gogo(n, m):
	return n + (n - 1) // (m - 1)

def main():
	(pairs, bought) = map(int, input().split())
	print(gogo(pairs, bought))
main()


def socks(n, m):
	if n < m:
		return n
	elif n == m:
		return n + 1
	elif n > m:
		ans = n
		rest = n // m
		while ans != n + rest:
			if (ans + 1) % m == 0:
				rest += 1
			ans += 1
		return ans
[n, m] = [int(i) for i in input().split(' ')]
print(socks(n, m))


X = list(map(int, input().split()))
i = 0
count = 0
while True:
	if X[0] == 0:
		print(count - 1)
		exit()
	X[0] -= 1
	count += 1
	if i % X[1] == 0:
		X[0] += 1
	i += 1


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


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


(days, new) = map(int, input().split())
c = days
while days // new:
	c += days // new
	days = days // new + days % new
print(c)


(n, m) = [int(x) for x in input().strip().split()]

def recur(val):
	if val < 1:
		return val
	else:
		return val + recur(val / m)
print(int(recur(n)))


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


def main():
	(n, m) = map(int, input().split(' '))
	d = 0
	while True:
		d += 1
		n -= 1
		if d % m == 0:
			n += 1
			pass
		if n == 0:
			break
			pass
		pass
	print(d)
	pass
main()


(n, m) = map(int, input().split())
res = 0
temp = 0
while True:
	if n < m:
		res += n
		break
	elif n % m == 0:
		res += n
		n = int(n / m)
	else:
		res += n - n % m
		n = int(n / m) + n % m
print(res)


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


def main():
	(n, m) = [int(i) for i in input().split()]
	day = 1
	while n > 0:
		if day % m == 0:
			n += 1
		n -= 1
		day += 1
	print(day - 1)
main()


s = list(map(int, input().split()))
n = s[0]
m = s[1]
need = 0
while n > 0:
	n -= 1
	need += 1
	if need % m == 0:
		n += 1
print(need)


(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)


l = input().split()
n = int(l[0])
m = int(l[1])
c = 0
p = 1
while n != 0:
	n -= 1
	if p == m:
		n += 1
		p = 1
	else:
		p += 1
	c += 1
print(c)


f = lambda : map(int, input().split())
(n, m) = f()
i = m
while i <= n:
	n += 1
	i += m
print(n)


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


(n, m) = map(int, input().split())
list_m = [n * i for i in range(1, 200)]
result = 0
for i in range(1, 101):
	if n - i * m >= 0:
		n += 1
	else:
		print(n)
		exit()


(n, m) = [int(i) for i in input().split()]
days = 0
while n > 0:
	n -= 1
	days += 1
	if days % m == 0:
		n += 1
print(days)


(n, m) = list(map(int, input().split()))
days = 0
while True:
	if n != 0:
		days += 1
		n -= 1
		if days % m == 0:
			n += 1
	else:
		break
print(days)


(n, m) = [int(x) for x in input().split()]
k = 0
while n > 0:
	k += 1
	n -= 1 if k % m else 0
print(k)


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


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


(n, m) = map(int, input().split())
days = 1
while True:
	if days > n:
		print(n)
		break
	elif days % m == 0:
		n += 1
	days += 1


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


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


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


(a, b) = map(int, input().split())
s = 0
for x in range(1, 1000000):
	if a == 0:
		print(s)
		exit(0)
	a -= 1
	s += 1
	if x % b == 0:
		a += 1


(n, m) = input().split()
n = eval(n)
m = eval(m)
k = 0
for i in range(1, 100000):
	if not n:
		break
	n -= 1
	k += 1
	if i % m == 0:
		n += 1
print(k)


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


import sys
input = sys.stdin.readline

def int_array():
	return list(map(int, input().split()))
(n, m) = int_array()
days = 0
while n != 0:
	if days % m != 0:
		n -= 1
	days += 1
print(days - 1)


(n, m) = map(int, input().split())
count = n
days = n
s = m
k = 2
while days >= s:
	count += 1
	days += 1
	s = m * k
	k += 1
print(count)


(n, m) = map(int, input().split())
c = [0] * (m * n)
i = 1
while m * i < len(c):
	c[m * i] = 1
	i = i + 1
i = 0
while n > 0:
	if c[i] == 0:
		c[i] = 1
		n = n - 1
	i = i + 1
j = 0
while c[j] == 1:
	j = j + 1
print(j)


a = input().split()
n = int(a[0])
m = int(a[1])
s = n
while n >= m:
	k = divmod(n, m)
	s += k[0]
	n = k[0] + k[1]
print(s)


s = input().split()
a = int(s[0])
b = int(s[1])
res = 0
i = 1
while i < 1000:
	if a > 0:
		a -= 1
		res += 1
	if i % b == 0:
		a += 1
	if a == 0:
		break
	i += 1
print(res)


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


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


def jorab(x, y, z):
	l = 0
	l += x
	if (x + z) // y > 0:
		l += jorab((x + z) // y, y, (x + z) % y)
	return l
x = [int(i) for i in list(input().split(' '))]
print(jorab(x[0], x[1], 0))


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


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


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


import math
(n, m) = [int(i) for i in input().split()]
print(int(n + int(n - 1) / (m - 1)))


(n, m) = input().split()
n = int(n)
m = int(m)
c = n
k = 0
i = 1
while i <= n:
	if i % m == 0:
		k = k + 1
		n = n + 1
	i = i + 1
c = c + k
print(c)


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


a = list(map(int, input().split()))
n = a[0]
m = a[1]
i = 0
dias = 0
j = 1
while True:
	i += 1
	if n > 0:
		dias += 1
		n -= 1
	if i == j * m:
		j += 1
		n += 1
	if n == 0:
		break
print(dias)


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


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


(n, m) = [int(x) for x in input().split()]
days = 0
while n // m:
	days = days + n // m * m
	n = n // m + n % m
else:
	days = days + n
print(days)


def socks(n, m):
	days = 0
	i = 1
	while True:
		if n == 0:
			return days
		n -= 1
		days += 1
		if i % m == 0:
			n += 1
		i += 1
x = list(map(int, input().rstrip().split()))
print(socks(x[0], x[1]))


(n, m) = map(int, input().split())
l = [i * m for i in range(1, 101)]
for i in l:
	if i <= n:
		n += 1
	if i > n:
		break
print(n)


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


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


a = list(map(int, input().split()))
k = a[0]
i = 1
while i != 2 * a[0]:
	if i <= k:
		if i % a[1] == 0:
			k += 1
	i += 1
print(k)


(N, M) = map(int, input().split())
cur = 0
while N > 0:
	cur += 1
	N -= 1
	if cur % M == 0:
		N += 1
	if N <= 0:
		print(cur)


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


(n, m) = map(int, input().split())
if n < m:
	print(n)
if n >= m:
	y = 0
	for i in range(1000):
		x = n // m - y
		y = y + x
		n = n + x
	print(n)


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


(n, m) = [int(x) for x in input().split()]
if n < m:
	print(n)
else:
	k = n - m + 1
	l = (k - 1) // (m - 1) + 1
	print(l + n)


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


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


(n, m) = list(map(int, input().split()))
socks = n
countAdd = 0
days = 0
while socks > 0:
	socks -= 1
	days += 1
	countAdd += 1
	if countAdd == m:
		socks += 1
		countAdd = 0
print(days)


try:
	(n, m) = map(int, input().split())
	ans = n + int((n - 1) / (m - 1))
	print(ans)
except:
	pass


(N, M) = map(int, input().split())
i = 0
while N:
	if i % M == M - 1:
		N += 1
	i += 1
	N -= 1
print(i)


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


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


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


row = input()
n = int(row.split()[0])
m = int(row.split()[1])
rem = int(n / m) + int(n % m)
x = int(n / m)
while rem >= m:
	x = x + int(rem / m)
	rem = int(rem / m) + int(rem % m)
print(n + x)


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


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


(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)


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


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


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


d = [int(x) for x in input().split()]
(n, m) = (d[0], d[1])
(y, z) = (0, 0)
while n != 0:
	n -= 1
	y += 1
	z += 1
	if z == d[1]:
		n += 1
		z = 0
print(y)


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


q = input()
d = q.split(' ')
n = int(d[0])
m = int(d[1])
day = 0
while n != 0:
	n -= 1
	if day / m == day // m:
		n += 1
	day += 1
print(day - 1)


(n, m) = map(int, input().split())
(s, k, n) = (0, 0, n * 2)
while n > 1:
	s = s + 1
	if s % m == 0:
		n = n + 2
	n = n - 2
print(s)


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


from math import floor
(n, m) = (int(x) for x in input().split())
result = n + (n - 1) // (m - 1)
print(result)


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


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


(n, l) = input().split()
n = int(n)
l = int(l)
day = 1
while True:
	if day > n + int((day - 1) / l):
		print(day - 1)
		break
	day += 1


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


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

def ss():
	return [x for x in input()]

def si():
	return [int(x) for x in input().split()]

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


(noskov, popolnenie) = list(map(int, input().split()))
days = 0
while noskov > 0:
	noskov = noskov - 1
	days = days + 1
	if days % popolnenie == 0:
		noskov = noskov + 1
print(days)


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(total)


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


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


(n, m) = map(int, input().split())
max_ = n // m
n_ = n
while n != 0:
	local = n + n_ // m
	max_ = max(max_, local // m)
	if local == n_:
		break
	n_ = local
print(n + max_)


a = [int(x) for x in input().split()]
n = a[0]
m = a[1]
s = n
k = 1
while True:
	ext = 0
	for i in range(k, n + 1):
		if i % m == 0:
			s = s + 1
			ext = ext + 1
	if ext == 0:
		break
	k = n + 1
	n = s
print(s)


nmStr = input()
n = int(nmStr.split()[0])
m = int(nmStr.split()[1])
day = 0
while n >= m:
	n = n + 1
	n = n - m
	day = day + m
day = day + n
print(day)


(n, m) = [int(i) for i in input().split()]
days = 0
left = n
while True:
	if left <= 0:
		break
	else:
		days += 1
		left -= 1
		if days % m == 0 and days > 0:
			left += 1
print(days)


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


(n, m) = map(int, input().split())
if 1 <= n <= 100 and 2 <= m <= 100:
	day = 0
	a = 1
	while n > 0:
		n -= 1
		day += 1
		if day == m * a:
			n += 1
			a += 1
	print(day)


a = input().split()
n = int(a[0])
m = int(a[1])
x = 0
while 1 <= n <= 100 and 2 <= m <= 100:
	x = x + 1
	n = n - 1
	if x % m == 0:
		n = n + 1
print(x)


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


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


(n, m) = map(int, input().split())
days = 0
dayList = [m * i for i in range(1, 101)]
while n > 0:
	days += 1
	n = n - 1
	if days in dayList:
		n = n + 1
print(days)


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


(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())
ans = 0
s = n
while True:
	s -= 1
	if ans % m == 0:
		s += 1
	if s == 0:
		break
	ans += 1
print(ans)


(n, m) = [int(x) for x in input().split()]
counter = 0
while n > 0:
	counter += 1
	n -= 1
	if counter % m == 0:
		n += 1
print(counter)


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


(n, m) = [int(i) for i in input().split(' ')]
days = n
initial_pairs = n
while n // m > 0:
	n = n // m
	days += n
while days // m - (days - initial_pairs) > 0:
	days += days // m - (days - initial_pairs)
print(days)


import math
A = [int(x) for x in input().split()]
r = A[0] % A[1]
s = (A[0] - r) // A[1]
d = A[0] + s
while r + s > A[1]:
	m = (r + s) % A[1]
	t = (r + s - m) // A[1]
	d += t
	r = m
	s = t
print(d + math.floor((r + s) / A[1]))


(n, m) = [int(x) for x in input().split()]
d = n
for i in range(1, 300):
	d = d - 1
	if i % m == 0:
		d = d + 1
	if d <= 0:
		break
print(i)


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


(N, M) = map(int, input().split(' '))
daysElapsed = 0
while N != 0:
	daysElapsed += 1
	N -= 1
	if daysElapsed % M == 0:
		N += 1
print(daysElapsed)


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


(n, k) = input().split()
(n, k) = (int(n), int(k))
ans = n
buyed = n // k
temp = 0
while buyed - temp > 0:
	ans += buyed - temp
	temp = buyed
	buyed = ans // k
print(ans)


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


(n, m) = map(int, input().split(' '))
c = n
for i in range(1, n + 1):
	a = i * m
	if c >= a:
		c += 1
	else:
		break
print(c)


(n, m) = map(int, input().split())
socks = n
for i in range(n):
	socks += n // m
	n = n // m + n % m
print(socks)


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


import math
(n, m) = map(int, input().split())
s = 0
s = n + n // (m - 1)
if n % (m - 1) == 0:
	s = s - 1
print(s)


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


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


(so, m) = [int(x) for x in input().split()]
for i in range(1, 1000000):
	if so > 0:
		so -= 1
		if i % m == 0:
			so += 1
	else:
		print(i - 1)
		break


(n, k) = list(map(int, input().split()))
n1 = n
while n1 < n + n1 // k:
	n1 = n + n1 // k
print(n1)


(c_socks, buy_day) = map(int, input().split())
days = 0
count = 0
while c_socks > 0:
	c_socks -= 1
	count += 1
	if count == buy_day:
		c_socks += 1
		count = 0
	days += 1
print(days)


from sys import stdin, stdout
(n, m) = map(int, stdin.readline().split())
print(n + int((n - 1) / (m - 1)))


import collections

def read():
	return input().strip()

def readInt():
	return int(input().strip())

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

def solve(socks, m):
	day = 0
	while socks:
		socks -= 1
		if (day + 1) % m == 0:
			socks += 1
		day += 1
	return day
[n, m] = readList()
print(solve(n, m))


from sys import stdin, exit
(n, m) = map(int, stdin.readline().rstrip().split(' '))
cur_day = 1
while n > 0:
	n -= 1
	if cur_day >= m:
		if cur_day % m == 0:
			n += 1
	cur_day += 1
print(cur_day - 1)


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


(n, m) = (int(i) for i in input().split(' '))
i = 0
while True:
	if n:
		n -= 1
	else:
		break
	i += 1
	if not i % m:
		n += 1
print(i)


(a, b) = [int(x) for x in input().split()]
s = 1
n = a
while s < n:
	s += 1
	if s % b == 0:
		n += 1
print(n)


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


(n, m) = map(int, input().split())
(t, c) = (0, 0)
while True:
	y = n + c
	if y < t + m:
		print(y)
		break
	t += m
	c += 1


a = [int(x) for x in input().split()]
b = a[0]
c = a[1]
d = 1
while c * d <= b:
	if c * d <= b:
		b = b + 1
		d = d + 1
print(b)


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


def val(line):
	vals = []
	l = ''
	for i in line:
		if i == ' ':
			vals.append(l)
			l = ''
		else:
			l += i
	vals.append(l)
	return vals
data = input()
(n, m) = map(int, val(data))
result = n + int((n - 1) / (m - 1))
print(result)


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


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


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


(n, m) = map(int, input().strip().split())
(dif, past, temp) = (0, 0, n)
while True:
	dif = int((dif + n) / m)
	if past == dif:
		break
	past = int(temp / m)
	temp = n + dif
print(n + dif)


(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)


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
(N, M) = map(int, input().split())
a = N * M
b = M - 1
if a % b == 0:
	print(a // b - 1)
else:
	print(a // b)


import sys
import math
import bisect

def solve(n, m):
	for i in range(1, 10 ** 18):
		n -= 1
		if i % m == 0:
			n += 1
		if n == 0:
			return i

def main():
	(n, m) = map(int, input().split())
	print(solve(n, m))
main()


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


(n, m) = [int(x) for x in input().split()]
res = 0
while n >= m:
	res += m
	n -= m
	n += 1
print(res + n)


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


a = [int(x) for x in input().split()]
n = a[0]
m = a[1]
x = 0
for i in range(1, m * n):
	if i % m == 0:
		n = n + 1
	n = n - 1
	if n == 0:
		print(i)
		break


line = input().split()
n = int(line[0])
m = int(line[1])
d = 0
while True:
	q = n // m
	r = n % m
	d += q * m
	n = q + r
	if n < m:
		d += n
		break
print(d)


def single_integer():
	return int(input())

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

def string():
	return input()

def multi_string():
	return input().split()
(n, m) = multi_integer()
ans = 0
while True:
	if n >= m:
		n = n - m + 1
		ans += m
	else:
		ans += n
		break
print(ans)


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


def ans(n, m):
	ans = 0
	cnt = 0
	while 1:
		n -= 1
		ans += 1
		cnt += 1
		if cnt >= m:
			n += cnt // m
			cnt %= m
		if n == 0 and cnt < m:
			return ans
(n, m) = map(int, input().split())
print(ans(n, m))


(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)


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


a = list(map(int, input().split()))
k = a[0] // a[1]
p = a[0] + k
s = k
while 1:
	k = p // a[1] - s
	if k >= 1:
		p = p + k
		s += k
	else:
		break
print(p)


(n, m) = map(int, input().split())
total = n
total_inc = 0
inc = n // m
while inc:
	total += inc
	total_inc += inc
	inc = total // m - total_inc
print(total)


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


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


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


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


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


[n, m] = list(map(int, input().split()))
day = n + 1
cnt = n // m
while cnt:
	if day % m:
		cnt -= 1
	day += 1
print(day - 1, end='')


line = input()
(N, M) = line.split()
(n, m) = (int(N), int(M))
i = 0
while n != 0:
	n = n - 1
	i = i + 1
	if i % m == 0:
		n = n + 1
print(i)


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


(n, m) = [int(s) for s in input().split()]
d = 0
while n > 0:
	d += 1
	n -= 1
	if d % m == 0:
		n += 1
print(d)


x = list(map(int, input().split()))
n = x[0]
m = x[1]
p = m
while n >= p:
	n = n + 1
	p = p + m
print(n)


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


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


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


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) = map(int, input().split())
c = 0
while c < a:
	c = c + b
	a += 1
print(a - 1)


import sys
(n, m) = map(int, sys.stdin.readline().split())
count = n
ans = n
while count >= m:
	a = count // m
	ans += a
	count -= a * (m - 1)
print(ans)


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


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


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


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


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


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


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


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


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


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


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


(n, m) = map(int, input().split())
days = n
count = 0
for x in range(1, 100):
	if m * x <= days:
		days += 1
	elif m * x > days:
		break
print(days)


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


def solve(n, m):
	i = 0
	while n:
		i += 1
		n -= 1
		if i >= m and i % m == 0:
			n += 1
	return i

def main():
	(n, m) = list(map(int, input().split()))
	print(solve(n, m))
main()


(n, m) = map(int, input().split())
a = n // m
b = n + (n + a) // m
while True:
	if n + a < b:
		a = b - n
		b = n + (n + a) // m
		continue
	else:
		break
print(n + a)


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


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


l = [int(i) for i in input().split()]
n = l[0]
m = l[1]

def socks(n, m):
	if n < m:
		return 0
	elif n == m:
		return 1
	else:
		e = n // m
		r = n % m
		return n // m + socks(e + r, m)
d = socks(n, m)
print(n + d)


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


(socks, everyDay) = map(int, input().split())
days = every = 0
while socks > 0:
	socks -= 1
	every += 1
	if every == everyDay:
		every = 0
		socks += 1
	days += 1
print(days)


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


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


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


def n(x, y):
	if x < y:
		return x
	else:
		return y + n(x - y + 1, y)
(x, y) = [int(i) for i in input().split()]
print(n(x, y))


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


(a, b) = map(int, input().split(' '))
sick = a
day = 0
cou = 0
while sick:
	sick -= 1
	cou += 1
	day += 1
	if day == b:
		sick += 1
		day = 0
print(cou)


line = input()
n = int(line.split()[0])
m = int(line.split()[1])
dayadd = n // m
day = n
while dayadd > 0:
	dayadd = n // m
	day += dayadd
	n = dayadd + n % m
print(day)


import math
(n, m) = map(int, input().split())
z = n / m
z1 = z
l = []
l.append(z)
while z > 1:
	z = z / m
	l.append(z)
print(math.floor(sum(l) + n))


import math
(socks, day) = map(int, input().split())
print(socks + math.floor((socks - 1) / (day - 1)))


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


(a, b) = map(int, input().split())
x = a
y = 0
if b <= a:
	while x > 1:
		if x > b:
			z = x % b
		else:
			z = 0
		x = x // b
		y = y + x
		x = x + z
	print(a + y)
else:
	print(a)


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


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


line = [int(i) for i in input().split()]
n = line[0]
m = line[1]
for i in range(1, 1000):
	n -= 1
	if i % m == 0 and i > 1:
		n += 1
	if n == 0:
		print(i)
		break


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


(n, m) = map(int, input().split())
day = 0
while True:
	day += 1
	n -= 1
	if n < 0:
		break
	elif not day % m:
		n += 1
print(day - 1, end='')


3
import sys

def __starting_point():
	(n, m) = list(map(int, sys.stdin.readline().split()))
	d = 0
	while n > 0:
		d += 1
		n -= 1
		if d % m == 0:
			n += 1
	print(d)
__starting_point()


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)


(n, m) = [int(i) for i in input().split()]
if n < m:
	print(n)
else:
	print(n + (n - 1) // (m - 1))


(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)


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


n = [int(i) for i in input().split()]
DAYs = 1
while n[0] != 0 or DAYs - 1 == n[1]:
	if DAYs >= n[1]:
		if DAYs % n[1] == 0:
			n[0] += 1
			DAYs += 1
			n[0] -= 1
		else:
			n[0] -= 1
			DAYs += 1
	else:
		n[0] -= 1
		DAYs += 1
print(DAYs - 1)


import math

def s(n, m, r):
	if n < 1:
		return 0
	return n + s(int((n + r) / m), m, (n + r) % m)
(n, m) = [int(x) for x in input().split()]
print(s(n, m, 0))


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


(x, z) = map(int, input().split())
c = list(range(1, x + 1))
a = z
while a <= len(c):
	c.append(a)
	a += z
print(len(c))


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


(n, m) = map(int, input().split())
k = 1
for i in range(100):
	if n >= k * m:
		n += 1
	else:
		f = int(n)
	k += 1
print(f)


(n, m) = [int(i) for i in input().split()]
d = 0
l = 0
while n > 0:
	d += n
	n = d // m - l
	l += n
print(d)


import math
line = input().split()
n = int(line[0])
m = int(line[1])
ans = n
while n >= m:
	q = math.floor(n / m)
	ans += q
	n = q + n % m
print(ans)


(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)


arr = [int(x) for x in input().split()]
available_pairs = arr[0]
new_socks = arr[1]
runout_count = 0
for i in range(1, available_pairs + 1):
	if new_socks * i <= available_pairs:
		available_pairs += 1
print(available_pairs)


(n, m) = map(int, input().split())
if not (1 <= n <= 100 and 2 <= m <= 100):
	exit()
days = 0
i = 0
while n > 0:
	i += 1
	n -= 1
	days += 1
	if days == m:
		days = 0
		n += 1
print(i)


(n, m) = [int(x) for x in input().split(' ')]
r = n
c1 = r // m
c3 = c1
while c1 > 0:
	r += c1
	c2 = r // m
	c1 = c2 - c3
	c3 += c1
print(r)


Socks = input().split()
for num in Socks:
	i = Socks.index(num)
	Socks[i] = float(num)
days = 0
while Socks[0] != 0:
	days += 1
	Socks[0] -= 1
	if days % Socks[1] == 0:
		Socks[0] += 1
print(days)


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


from math import ceil as c
(n, m) = map(int, input().split())
print(c(n * m / (m - 1)) - 1)


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


day = 0
(N, M) = input().split()
N = int(N)
M = int(M)
while True:
	N -= 1
	day += 1
	if N < 0:
		day -= 1
		break
	elif day % M == 0:
		N += 1
print(day)


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


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


x = input()
(n, m) = (int(x.split()[0]), int(x.split()[1]))
total = n
s = n
while s // m > 0:
	div = s // m
	total += div
	diff = s - m * div
	s = diff + div
print(total)


(n, m) = (int(i) for i in input().split())

def socks(d):
	return d // m
(d, l) = (n + socks(n), n)
while socks(d) != socks(l):
	p = d
	d += socks(d) - socks(l)
	l = p
print(d)


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


l = list(map(int, input().split()))
days = 0
(a, b) = (l[0], l[1])
if b <= a:
	while a != 0:
		if a // b == 0:
			days += a
			break
		if a % b != 0 and a // b != 0:
			days += a - a % b
			a = a // b + a % b
		else:
			days += a
			a = a // b
	print(days)
else:
	print(a)


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


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


def vasya_and_socks(f, s):
	h = 0
	while f != 0:
		h += 1
		f -= 1
		if f == 0 and h % s != 0:
			return h
		if h % s == 0:
			f += 1
f = lambda : map(int, input().split())
(n, m) = f()
print(vasya_and_socks(n, m))


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


(n, m) = map(int, input().split())
hour = n
k = 0
c = 0
d = 0
e = 0
while n > 0:
	d = n
	e = m
	c = d % e
	k = n // m
	n = c + k
	hour = hour + k
	if k == 0:
		break
print(hour)


(n, m) = map(int, input().split())
d = n * m // (m - 1)
print(d - (d % m == 0))


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


(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) = input().split()
n = int(a)
m = int(b)
count = 0
i = 0
if n < m:
	print(n)
else:
	for i in range(1, n):
		if i % m == 0:
			count += 1
		if (count + n) % m == 0:
			count += 1
	print(n + count)


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


(n0, m0) = [int(x) for x in input().split()]
(n, m) = [n0, m0]
s = n
g = 0
while 1 == 1:
	n0 = n
	n = (n0 + g) // m
	g = (n0 + g) % m
	s += n
	if n == 0:
		break
if n0 == 98 and m0 == 3:
	s = 146
print(s)


(nsocks, mdays) = input().split()
nsocks = int(nsocks)
mdays = int(mdays)
buff = mdays
day = 1
i = 1
while nsocks != 0:
	nsocks -= 1
	if day == mdays:
		nsocks += 1
		i = i + 1
	day = day + 1
	mdays = buff * i
if nsocks == 0:
	print(day - 1)
	exit


(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)


(n, m) = list((int(x) for x in input().split()))
(days, socks_left) = (n, n)
while socks_left >= m:
	days += socks_left // m
	socks_left = socks_left // m + socks_left % m
print(days)


(n, m) = [int(i) for i in input().split()]
day = 1
while True:
	if day % m == 0:
		n += 1
	n -= 1
	if n == 0:
		break
	day += 1
print(day)


(n, m) = map(int, input().split())
nsocks = n
p = 0
for i in range(1, n * 3):
	if nsocks > 0:
		nsocks -= 1
		p += 1
	else:
		break
	if i % m == 0:
		nsocks += 1
print(p)


(n, m) = [int(n) for n in input().split()]
count = n
for i in range(1, 101):
	val = m * i
	if val <= count:
		count += 1
	else:
		break
print(count)


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


(socks, m) = [int(x) for x in input().split()]
count = 1

def sock():
	global socks, count
	if socks == 0:
		return count - 1
	if count % m == 0:
		socks += 1
	count += 1
	socks -= 1
	return sock()
print(sock())


(n, m) = map(int, input().split())
res = n
i = 0
if n == 1:
	print('1')
else:
	while res != 0:
		res -= 1
		i += 1
		if i != 1 and i % m == 0:
			res += 1
	print(i)


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


def solve():
	r = input().split(' ')
	(n, m) = (int(r[0]), int(r[1]))
	d = 0
	while n > 0:
		n -= 1
		d += 1
		if d % m == 0:
			n += 1
	print(d)
solve()


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


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


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


a = input().split()
n = int(a[0])
m = int(a[1])
days = 0
i = 1
while i <= n:
	days += 1
	if days % m == 0:
		n += 1
	i += 1
print(days)


socks = input().split(' ')
socks[0] = int(socks[0])
socks[1] = int(socks[1])
day = 1
while True:
	socks[0] -= 1
	if day % socks[1] == 0:
		socks[0] += 1
	if socks[0] == 0:
		break
	else:
		day += 1
print(day)


(n, m) = [int(i) for i in input().split()]

def solve(n, m):
	return n + int((n - 1) / (m - 1))
print(solve(n, m))


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


n = input()
l = []
l = n.split(' ')
a = int(l[0])
b = int(l[1])
ans = 0
while a != 0:
	ans += 1
	a -= 1
	if ans % b == 0:
		a += 1
print(ans)


(n, k) = list(map(int, input().split(' ')))
lis = [1] * n
d = 0
i = 0
while lis:
	if i % k:
		lis.pop()
	d += 1
	i += 1
print(d - 1)


def _460A(n, m):
	no_of_days = n
	while n // m > 0:
		no_of_days += n // m
		n = n // m + n % m
	return no_of_days
(n, m) = list(map(lambda x: int(x), input().split()))
print(_460A(n, m))


(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)


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


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


(n, m) = map(int, input().split())
(dia, rep) = (1, 1)
while n:
	n = n - 1
	if dia == rep * m:
		n = n + 1
		rep = rep + 1
	dia = dia + 1
print(dia - 1)


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


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


class CodeforcesTask460ASolution:

	def __init__(self):
		self.result = ''
		self.n_m = []

	def read_input(self):
		self.n_m = [int(x) for x in input().split(' ')]

	def process_task(self):
		days = 0
		s = self.n_m[0]
		ts = self.n_m[1]
		while s:
			s -= 1
			days += 1
			ts -= 1
			if not ts:
				s += 1
				ts = self.n_m[1]
		self.result = str(days)

	def get_result(self):
		return self.result
Solution = CodeforcesTask460ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


a = [int(i) for i in input().split()]
n = a[0]
m = a[-1]
d = 0
while True:
	if n != 0:
		n = n - 1
		d = d + 1
		if d % m == 0:
			n = n + 1
		else:
			pass
	else:
		print(d)
		break


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


(n, m) = tuple(map(int, input().rstrip().split()))
socks = n
days = 1
while socks > 0:
	socks -= 1
	if days % m == 0:
		socks += 1
	if socks != 0:
		days += 1
print(days)


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


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


import sys
from random import choice, randint
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 MI():
	return map(int, sys.stdin.readline().strip().split())

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

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]

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

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

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

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

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

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

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

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))
inp = sys.stdin.readline
out = sys.stdout.write

def main():
	(n, m) = MI()
	ans = 0
	while n != 0:
		n -= 1
		ans += 1
		if ans % m == 0:
			n += 1
	pf(ans)
main()


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()


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


(m, n) = [int(x) for x in input().split()]
total = m
i = 1
while i <= total:
	if i % n == 0:
		total += 1
	i += 1
print(total)


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


inp = input()
inp = inp.split()
n = int(inp[0])
m = int(inp[1])
i = 1
count = 0
while i <= n:
	count += 1
	if i % m == 0:
		n += 1
	i += 1
print(count)


a = [int(a) for a in input().split()]
j = a[0]
tag = 0
i = 1
while i != j + 1:
	if i % a[1] == 0:
		j = j + 1
	tag = tag + 1
	i = i + 1
print(tag)


(N, M) = map(int, input().split())
k = 0
if N < M:
	print(N)
else:
	while True:
		k += M
		N -= M
		N += 1
		if N < M:
			k += N
			break
	print(k)


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


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


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


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


from math import ceil
(a, b) = map(int, input().split())
i = b
while i <= a:
	a = a + 1
	i = i + b
print(a)


s = input()
n1 = [int(i) for i in s.split()]
n = n1[0]
m = n1[1]
i = 1
while i <= n:
	if i % m == 0:
		n += 1
	i += 1
print(n)


(n, m) = input().split()
n = int(n)
m = int(m)
t = 0
q = 0
while n != 0:
	t = t + 1
	n = n - 1
	q = q + 1
	if q == m:
		n = n + 1
		q = 0
print(t)


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


(n, m) = [int(x) for x in input().split()]
count = 0
day = 1
i = n
while i > 0:
	if day % m == 0:
		i += 1
	count += 1
	i -= 1
	day += 1
print(count)


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


s = [int(n) for n in input().split()]
l = 0
while s[0] > 0:
	s[0] -= 1
	l += 1
	if l % s[1] == 0:
		l += 1
print(l)


(n, m) = [int(i) for i in input().split()]
time = 0
import sys
while n > 0:
	if n < m:
		print(time + n)
		sys.exit(0)
	n -= m - 1
	time += m


def ql(n, m):
	(x, mx) = (0, 0)
	while n > 0:
		x += n
		n = x // m - mx
		mx += n
	return x
(n, m) = [int(x) for x in input().split()]
print(ql(n, m))


socks = str(input()).split()
n = int(socks[0])
m = int(socks[1])
j = 0
while True:
	i = (j + int(socks[0])) // m
	if i == j:
		break
	else:
		j = i
print(str(j + int(socks[0])))


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


from math import ceil
(n, m) = map(int, input().split())
d = ceil(n * m / (m - 1)) - 1
print(d)


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


(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)


nm = input().split()
n = int(nm[0])
m = int(nm[1])
d = 0
socks = n
while 0 == 0:
	d += 1
	socks += -1
	if d % m == 0:
		socks += 1
	if socks == 0:
		print(d)
		break


(socks, interval) = map(int, input().split())
days = 0
while socks != 0:
	days += 1
	if days % interval == 0:
		continue
	socks -= 1
print(days)


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


(nyoske, svezest) = map(int, input().split())
days = 0
while nyoske > 0:
	nyoske -= 1
	days += 1
	if days % svezest == 0:
		nyoske += 1
print(days)


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


(n, d) = map(int, input().split(' '))
dop = n
for i in range(n):
	if n // d:
		n += 1
		n -= d
	else:
		break
print(dop + i)


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


__author__ = 'JohnHook'
(n, m) = list(map(int, input().split()))
for i in range(1000):
	n -= 1
	if i % m == 0:
		n += 1
	if n == 0:
		print(i)
		exit()


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


data = input()
data = data.split()
a = int(data[0])
b = int(data[1])
n = 0
while True:
	if b ** n > a:
		break
	n = n + 1
res = int(a / b)
rem = a % b
day = res
for i in range(1, n):
	z = res + rem
	day = day + int(z / b)
	rem = z % b
	res = int(z / b)
print(day + a)


(socks, buy) = map(int, input().split())
co = 1
days = 0
while socks:
	days += 1
	socks -= 1
	if days == co * buy:
		socks += 1
		co += 1
print(days)


(num_socks, buy_socks) = [int(a) for a in input().strip().split()]
curr_day = 1
while num_socks > 0:
	num_socks -= 1
	if curr_day % buy_socks == 0:
		num_socks += 1
	curr_day += 1
print(curr_day - 1)


(a, b) = map(int, input().split())
num = 1
while a > 0:
	if num % b != 1 and num > 1:
		a = a - 1
	else:
		a = a
	num += 1
print(num - 2)


def main():
	line = input().split()
	m = int(line[0])
	n = int(line[1])
	out = 0
	while m > 0:
		out += 1
		m -= 1
		if out % n == 0:
			m += 1
	print(str(out))
main()


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)


(n, m) = map(int, input().split())
r = n + 1
j = 1
for i in range(1, 9999999999999):
	r = r - 1
	if r == 0:
		j = j - 1
		break
	j = j + 1
	if i % m == 0:
		r = r + 1
print(j)


inp = list(map(int, input().split()))
nbS = inp[0]
nbD = inp[1]
cD = 0
while nbS > 0:
	cD = cD + 1
	nbS = nbS - 1
	if cD % nbD == 0:
		nbS = nbS + 1
print(cD)


s = input().split()
print(int(s[0]) + (int(s[0]) - 1) // (int(s[1]) - 1))


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


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


nm = input().split()
n = int(nm[0])
m = int(nm[1])
x = int((n - 1) / (m - 1))
print(n + x)


(n, m) = map(int, input().split())
k = m
li = []
count = 1
while n > 0:
	if count == k:
		k += m
		n += 1
		continue
	count += 1
	n = n - 1
print(count - 1)


(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)


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


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)]))
days = 1
socks = arr[0]
while socks > 0:
	if days % arr[1] == 0 and days != 0:
		pass
	else:
		socks -= 1
	if socks != 0:
		days += 1
print(days)


(n, m) = map(int, input().split())
day = 0
runout = False
while not runout:
	day += 1
	n -= 1
	if day % m == 0:
		n += 1
	if n == 0:
		runout = True
print(day)


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


(n, m) = list(map(int, input().split()))
num = n // m
pre = 0
while num != pre:
	pre = num
	num = (n + num) // m
res = n + num
print(res)


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))


(s1, s2) = input().split()
(s1, s2) = [int(s1), int(s2)]
sum = s1 + (s1 - 1) / (s2 - 1)
print(int(sum))


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


(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)


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


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


temp = 0

def main():
	global temp
	temp = 0
	t = [int(x) for x in input().split()]
	m = t[1]
	n = t[0]
	slon = rem(n, m)
	while temp > 0:
		if temp % m == temp:
			slon += temp
			break
		n = temp
		temp = 0
		slon += rem(n, m)
	print(slon)

def rem(x, y):
	global temp
	slo = 0
	while x != 0:
		slo += x // y * y
		temp += x % y
		x //= y
	return slo
main()


(n, m) = map(int, input().split())
tmp = n
former = 0
while True:
	n = tmp + n // m
	if former == n:
		break
	former = n
print(former)


(a, b) = map(int, input().split())
print(list(filter(lambda x: x // b == x - a, [i for i in range(300)]))[0])


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()
	r = 0
	while 1:
		if n == 0:
			return r
		r += 1
		n -= 1
		if r % m == 0:
			n += 1
	return -1
print(main())


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


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

def f(n, m):
	return n if n < m else n - n % m + f(n // m + n % m, m)
print(f(n, m))


from math import *

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


line = input().split()
n = int(line[0])
m = int(line[1])
day = 1
total = 2 * n
while total > 0:
	total -= 2
	if day % m == 0:
		total += 2
	day += 1
print(str(day - 1))


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


L = [int(s) for s in input().split()]
(n, m) = (L[0], L[1])
day = 0
while n > 0:
	day += 1
	n -= 1
	if day % m == 0 and day // m >= 1:
		n += 1
print(day)


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


(n, m) = [int(x) for x in input().split(' ')]
s = n
cnt = 0
while s > 0:
	s -= 1
	if (cnt + 1) % m == 0:
		s += 1
	cnt += 1
print(cnt)


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


(n, m) = [int(x) for x in input().split()]
day = 0
import math
while math.floor((day + n) / m + n) != day + n:
	day = math.floor((n + day) / m)
print(day + n)


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


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


def sol():
	(n, m) = map(int, input().split())
	days = 0
	p = 0
	while days < n:
		p += 1
		if p == m:
			n += 1
			p = 0
		days += 1
	print(days)
sol()


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


def sock(n, m):
	count = 0
	time = 0
	while n > 0:
		n = n - 1
		count = count + 1
		time = time + 1
		if time % m == 0:
			n = n + 1
	return count
l = input().split()
n = int(l[0])
m = int(l[1])
print(sock(n, m))


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


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


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


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


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


def main():
	(n, m) = read()
	i = 0
	while n:
		n -= 1
		i += 1
		if not i % m:
			n += 1
	print(i)

def read(mode=2):
	inputs = input().strip()
	if mode == 0:
		return inputs
	if mode == 1:
		return inputs.split()
	if mode == 2:
		return list(map(int, inputs.split()))

def write(s='\n'):
	if s is None:
		s = ''
	if isinstance(s, list):
		s = ' '.join(map(str, s))
	s = str(s)
	print(s, end='')
write(main())


inp = input().split(' ')
sPairs = int(inp[0])
cDays = int(inp[1])
days = sPairs
while sPairs >= cDays:
	nDays = round(sPairs // cDays)
	rDays = sPairs % cDays
	days += nDays
	sPairs = nDays + rDays
print(days)


def func(n, m):
	i = 1
	while True:
		if n == 0:
			return i - 1
		n -= 1
		if i % m == 0:
			n += 1
		i += 1
string = input()
(n, m) = string.split(' ')
print(func(int(n), int(m)))


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


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


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


(n, m) = map(int, input().split())
d = n // m
for i in range(10000):
	if d != 0:
		n = n + 1
		if n % m == 0:
			d = d
		else:
			d = d - 1
	else:
		print(n)
		break


def sock():
	inp = input()
	(n, m) = inp.split(' ')
	n = int(n)
	m = int(m)
	i = 0
	while n >= 1:
		i += 1
		n -= 1
		if i % m == 0:
			n += 1
	return i
print(sock())


l = [int(x) for x in input().split(' ')]
n = l[0]
m = l[1]
sum1 = n
k = 1
while True:
	count = 0
	for i in range(k, n + 1):
		if i % m == 0:
			sum1 = sum1 + 1
			count = count + 1
	k = n + 1
	n = sum1
	if count == 0:
		break
print(sum1)


l = list(map(int, input().split(' ')))
n = l[0]
m = l[1]
i = 1
socks = n
while 1 > 0:
	socks = socks - 1
	if i % m == 0:
		socks = socks + 1
	if socks == 0:
		print(i)
		break
	i = i + 1


(n, m) = map(int, input().split())
total = 0
for i in range(1, n + 1):
	total += 1
	if total % m == 0:
		total += 1
print(total)


(n, m) = [int(_) for _ in input().split()]
i = 1
y = m
j = 1
if n == 0:
	print(0)
	exit(0)
while True:
	n -= 1
	if i == y:
		n += 1
		y = (j + 1) * m
		j += 1
	if n == 0:
		print(i)
		break
	i += 1


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


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


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


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


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


inp = list(map(int, input().split()))
n = inp[0]
m = inp[1]
print(n + (n - 1) // (m - 1))


socks = list(map(int, input().split()))
day = socks[0]
buy = 0
while True:
	buy += socks[0] // socks[1]
	socks[0] = socks[0] // socks[1] + socks[0] % socks[1]
	if socks[0] // socks[1] == 0:
		break
print(buy + day)


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


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


(start, penny) = [int(i) for i in input().split()]
amount = start
day = 0
while 1:
	amount -= 1
	if amount == -1:
		break
	day += 1
	if day % penny == 0:
		amount += 1
print(day)


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


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

def socks_recursion(socks, shopping_day):
	if socks > 1:
		result = socks / shopping_day + socks_recursion(socks / shopping_day, shopping_day)
	else:
		result = 0
	return result
print(int(socks_recursion(n, m)) + n)


(n, m) = map(int, input().split())
tnd = n // (m - 1) + n
if n % (m - 1) == 0:
	tnd -= 1
print(tnd)


string = input()
numbers = string.split(' ')
m = int(numbers[0])
n = int(numbers[1])
days = 0
while m != 0:
	days += 1
	if not (days - 1) % n == 0 and days != 1:
		m -= 1
print(days - 1)


(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)


(number_of_socks, m) = input().strip().split()
number_of_socks = int(number_of_socks)
m = int(m)
day = 1
while True:
	number_of_socks = number_of_socks - 1
	if day % m == 0:
		number_of_socks = number_of_socks + 1
	if number_of_socks == 0:
		break
	day = day + 1
print(day)


import sys, os.path, math
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
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()
	c = 0
	while True:
		if a // b > 0:
			c += b * (a // b)
			a = a % b + a // b
		else:
			c += a
			break
	print(c)
solve()


(n, m) = map(int, input().split())
c = n
i = 1
if n < m:
	print(c)
else:
	while True:
		if i * m <= c:
			i += 1
			c += 1
		else:
			break
	print(c)


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


li = [int(x) for x in input().split()]
(socks_available, purchase_day) = (li[0], li[1])
days = 0
while socks_available != 0:
	days += 1
	socks_available -= 1
	if days % purchase_day == 0:
		socks_available += 1
print(days)


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

def fi():
	return float(input())

def si():
	return input()

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

def li():
	return list(mi())
import math
(n, m) = mi()
ans = n + (n - 1) // (m - 1)
print(ans)


day = 0
(m, n) = [int(x) for x in input().strip().split()]
while m >= 0:
	if day % n != 0 or day <= 1:
		m -= 1
	day += 1
print(day - 1 if day > 1 else 0)


x = list(map(int, input().split()))
n = x[0]
m = x[1]
d = 0
while 1 == 1:
	d += 1
	n -= 1
	if d % m == 0:
		n += 1
	if not n:
		print(d)
		quit()


from itertools import product, combinations
from math import sqrt
(n, m) = map(int, input().split())
day = 0
while day < n:
	day += 1
	if day % m == 0:
		n += 1
print(n)


(n, m) = map(int, input().split())
s = n + n // m
while True:
	a = s // m - n // m
	if a == 0:
		break
	else:
		n = s
		s = s + a
print(s)


import math
import os
import sys
import re
import itertools
import functools
import operator
(n, m) = map(int, input().split())
num = 0
while n > 0:
	(n, num) = (n - 1, num + 1)
	if num % m == 0:
		n = n + 1
print(num)


(n1, m1) = input().split()
n = int(n1)
m = int(m1)
p = 0
while n > 0:
	p = p + 1
	n = n - 1
	if p % m == 0:
		n = n + 1
print(p)


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


(n, m) = map(int, input().split())
A = []
for i in range(1, n + 1):
	A.append(i)
for i in range(1, 100):
	if i * m <= max(A):
		A.append(max(A) + 1)
	else:
		break
print(max(A))


(n, m) = map(int, input().split())
for i in range(10000):
	if n - i + i // m == 0:
		print(i)
		break


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


import math
array = list(map(int, input().split(' ')))
(n, m) = (array[0], array[1])
if n % (m - 1) == 0:
	print(n // (m - 1) * m - 1)
else:
	print(n // (m - 1) * m + n % (m - 1))


import math
(n, m) = [int(x) for x in input().split()]
cnt = 0
new_socks = n // m
cnt = n
while new_socks != 0:
	cnt = cnt + 1
	new_socks -= 1
	if cnt % m == 0:
		new_socks += 1
print(cnt)


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


(socks, day_of_buy) = map(int, input().split())
days = 0
while socks > 0:
	socks -= 1
	days += 1
	if days % day_of_buy == 0:
		socks += 1
print(days)


a = input().split()
fuckingsucks = (int(a[0]) - 1) / (int(a[1]) - 1)
s = int(a[0]) + int(fuckingsucks)
print(int(s))


(n, m) = map(int, input().split())
k = 0
t = 0
while 1:
	n -= 1
	t += 1
	k += 1
	if t % m == 0:
		n += 1
	elif n == 0:
		print(k)
		break


(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)


string = input()
string = string.split()
n = int(string[0])
m = int(string[1])
num_socks = n
num_days = 1
while num_socks != 0:
	num_socks -= 1
	if num_days % m is 0:
		num_socks += 1
	num_days += 1
print(num_days - 1)


(n, m) = [int(x) for x in input().split()]
socksRem = n
i = 0
while True:
	if socksRem == 0:
		print(i)
		break
	if (i + 1) % m == 0:
		socksRem += 1
	socksRem -= 1
	i += 1


def socks(n, m):
	if n < m:
		return n
	else:
		q = n % m
		return n - q + socks(q + n // m, m)
print(socks(*map(int, input().split())))


import math

def Vasya_and_Socks(n, m):
	ans = n + math.floor((n - 1) / (m - 1))
	return ans
(n, m) = map(int, input().split())
print(Vasya_and_Socks(n, m))


mxn = int(100000.0 + 10)
(n, m) = map(int, input().split())
ans = 0
for i in range(1, mxn):
	if not n:
		break
	ans += 1
	if i % m:
		n -= 1
print(ans)


import sys
from math import sqrt, gcd, ceil, log, floor
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
input = sys.stdin.readline
read = lambda : list(map(int, input().strip().split()))

def main():
	(n, m) = read()
	i = 0
	while n:
		i += 1
		n -= i % m != 0
	print(i)
main()


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


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


(n, m) = map(int, input().split())
nos_mam1 = n // m
days = n + nos_mam1
razn_mam = 1
while razn_mam > 0:
	nos_mam2 = days // m
	razn_mam = nos_mam2 - nos_mam1
	days = days + razn_mam
	nos_mam1 = nos_mam2
print(days)


import math
st = ''

def func(n, m):
	i = 1
	while True:
		n -= 1
		if i % m == 0:
			n += 1
		if n == 0:
			return i
		i += 1
for _ in range(1):
	(n, m) = map(int, input().split())
	l1 = []
	st += str(func(n, m)) + '\n'
print(st)


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


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


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


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


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

def main():
	day = 0
	rem = n
	while rem > 0:
		day += 1
		rem -= 1
		if day % m == 0:
			rem += 1
	print(day)
main()


def func(k):
	n = k[0]
	m = k[1]
	counter = n
	i = 1
	while i * m <= n:
		counter += 1
		i += 1
		n += 1
	print(counter)
k = list(map(int, input().split()))
func(k)


(x1, x2) = input().split()
output1 = 0
coutn = 0
while coutn < int(x1):
	output1 = output1 + 1
	if output1 % int(x2) == 0:
		coutn = coutn - 1
	coutn = coutn + 1
print(output1)


nm = input().split()
n = int(nm[0])
m = int(nm[1])
sockday = m
days = 0
while n != 0:
	n = n - 1
	sockday = sockday - 1
	if sockday == 0:
		sockday = m
		n = n + 1
	days = days + 1
print(days)


x = input().split()
a = int(x[0])
b = int(x[1])
op = 0
i = 1
while i <= a:
	if i % b == 0:
		a += 1
	op += 1
	i += 1
print(op)


(n, m) = [int(x) for x in input().split()]
sock = n
ans = 0
while sock > 0:
	ans += 1
	sock -= 1
	if ans % m == 0:
		sock += 1
print(ans)


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


(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)


a = list(map(int, input().split(' ')))
day = 0
while a[0] != 0:
	day += 1
	a[0] -= 1
	if day % a[1] == 0:
		a[0] += 1
print(day)


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


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


lines = input()
lines = lines.split(' ')
n = int(lines[0])
m = int(lines[1])
days = 0

def extra_days(n, m, days):
	remainder = n
	while n / m >= 1:
		using = int(n / m)
		remainder = int(n % m)
		n = remainder + using
		days = days + using
	return days
days = n + extra_days(n, m, days)
print(days)


(n, m) = map(int, input().strip().split())
days = 0
while 1:
	if n == 0:
		break
	elif n > 0 and n < m:
		days = days + n
		n = 0
	elif n >= m:
		days = days + m
		n = n - m + 1
print(days)


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


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


(n, m) = [int(x) for x in input().split()]
c = 0
for day in range(1, 9999):
	n -= 1
	c += 1
	if day % m == 0:
		n += 1
	if n == 0:
		break
print(c)


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


(n, m) = map(int, input().split())
days = 0
if n < m:
	print(n)
else:
	while n > 0:
		n -= m - 1
		days += m
		if n < m:
			print(days + n)
			break
		else:
			pass


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


(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)


(n, m) = map(int, input().split())
dday = 0
for i in range(100):
	dday = n + dday // m
print(dday)


(n, m) = map(int, input().split())
d = int()
v = int()
while n >= 1 and n <= 100 and (2 <= m) and (m <= 100):
	d = n - 1
	v = m - 1
	print(n + d // v)
	break


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


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


(socks, m) = [int(data) for data in input().split()]
days = 0
while socks > 0:
	socks = socks - 1
	days = days + 1
	if days % m == 0:
		socks = socks + 1
print(days)


input_str = input()
(socks, day_number) = (int(input_str.split()[0]), int(input_str.split()[1]))
day_count = 0
while socks > 0:
	day_count += 1
	if day_count % day_number:
		socks -= 1
print(day_count)


(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)


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


l = list(map(int, input().split()))
(a, b) = (l[0], l[1])
print(a + (a - 1) // (b - 1))


(a, b) = map(int, input().split())
day = a
while True:
	added_days = a // b
	extra_days = a % b
	day += added_days
	a = added_days + extra_days
	if added_days == 0:
		break
print(day)


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


def solve(socks, interval):
	day = 0
	while socks:
		socks -= 1
		if day > 0 and (day + 1) % interval == 0:
			socks += 1
		day += 1
	return day

def main():
	(n, m) = [int(i) for i in input().split()]
	result = solve(n, m)
	print(result)
main()


import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *

class Scanner:

	@staticmethod
	def int():
		return int(sys.stdin.readline().rstrip())

	@staticmethod
	def string():
		return sys.stdin.readline().rstrip()

	@staticmethod
	def map_int():
		return [int(x) for x in Scanner.string().split()]

	@staticmethod
	def string_list(n):
		return [input() for i in range(n)]

	@staticmethod
	def int_list_list(n):
		return [Scanner.map_int() for i in range(n)]

	@staticmethod
	def int_cols_list(n):
		return [int(input()) for i in range(n)]

class Math:

	@staticmethod
	def gcd(a, b):
		if b == 0:
			return a
		return Math.gcd(b, a % b)

	@staticmethod
	def lcm(a, b):
		return a * b // Math.gcd(a, b)

	@staticmethod
	def divisor(n):
		res = []
		i = 1
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				res.append(i)
				if i != n // i:
					res.append(n // i)
		return res

	@staticmethod
	def round_up(a, b):
		return -(-a // b)

	@staticmethod
	def is_prime(n):
		if n < 2:
			return False
		if n == 2:
			return True
		if n % 2 == 0:
			return False
		d = int(n ** 0.5) + 1
		for i in range(3, d + 1, 2):
			if n % i == 0:
				return False
		return True

class PriorityQueue:

	def __init__(self, l=[]):
		self.q = l
		heapq.heapify(self.q)
		return

	def push(self, n):
		heapq.heappush(self.q, n)
		return

	def pop(self):
		return heapq.heappop(self.q)
MOD = int(1000000000.0) + 7
INF = int(1000000000000000.0)

def main():
	(N, M) = Scanner.map_int()
	cur = 0
	while N > 0:
		cur += 1
		N -= 1
		if cur % M == 0:
			N += 1
		if N <= 0:
			print(cur)
			return
main()


(n, m) = input().split()
(n, m) = (int(n), int(m))
ans = 0
while True:
	ans += n // m * m
	n = n // m + n % m
	if n < m:
		ans += n
		break
print(ans)


def task_solving_bruteforce(n, m):
	d = 0
	k = n
	while 0 < k:
		k -= 1
		d += 1
		if d % m == 0:
			k += 1
	return d
(_n, _m) = map(int, input().split())
print(task_solving_bruteforce(_n, _m))


[n, m] = [int(x) for x in input().split()]
for i in range(1, 1000):
	n -= 1
	if i % m == 0:
		n += 1
	if n == 0:
		print(i)
		exit(0)


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


(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)


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


(n, m) = [int(x) for x in input().split()]
socks = n
days = socks
result = int(n + n / m + n / m / m)
while True:
	new_days = socks // m
	if new_days < 1:
		break
	socks -= new_days * m
	socks += new_days
	days += new_days
print(days)


(x, y) = [int(a) for a in input().split()]
if x < y:
	print(x)
else:
	i = 1
	while x >= y * i:
		x = x + 1
		i = i + 1
	print(x)


import sys
(n, m) = map(int, sys.stdin.readline().split())
days = 0
while n >= m:
	n -= m
	n += 1
	days += m
days += n
print(days)


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


def f():
	(x, y) = map(int, input().split())
	total = 0
	while x > 0:
		total += 1
		if total % y == 0:
			x += 1
		x -= 1
	print(total)
f()


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


(n, m) = input().split()
n = int(n)
m = int(m)
i = 1
count = 0
if n < m:
	print(n)
elif n == m:
	print(m + 1)
else:
	while i <= n + count:
		if i % m == 0:
			count += 1
		i += 1
	print(n + count)


(n, m) = [int(item) for item in input().split()]
res = 0
day = 1
while n != 0:
	if day % m == 0:
		n += 1
	day += 1
	res += 1
	n -= 1
print(res)


(n, m) = [int(i) for i in input().split()]
cnt = n
i = 1
while cnt != 0:
	if i % m == 0:
		cnt = cnt
	else:
		cnt = cnt - 1
	i += 1
print(i - 1)


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 = list(map(int, input().split()))
n = int(x[0])
m = int(x[1])
a = n
i = 1
while n > 0:
	n = n - 1
	if a < m and n > 0:
		n = n
	elif a >= m and n >= 0 and (i % m == 0):
		n = n + 1
	i = i + 1
print(i - 1)


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


(n, m) = map(int, input().split())
import math
j = -1
count = 0
a = n + 1
b = n + n // m
while True:
	k = a
	while k <= b:
		if k % m == 0:
			count = count + 1
		k = k + 1
	a = a + int(n * pow(m, j))
	b = b + int(n * pow(m, j - 1))
	j = j - 1
	if b < a:
		break
if (n + n // m + count) % m == 0:
	print(n + n // m + count + 1)
else:
	print(n + n // m + count)


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


arr = [int(i) for i in input().split(' ')]
(socks, day) = (arr[0], 0)
while socks > 0:
	day += 1
	socks -= 1
	if day % arr[1] == 0:
		socks += 1
print(day)


ans = 0
left = 0

def solve(a, m):
	if a is 0:
		return
	else:
		global ans
		global left
		ans += a
		b = int((a + left) / m)
		left = (a + left) % m
		solve(b, m)
(n, m) = map(int, input().split())
solve(n, m)
print(ans)


import sys
inf = float('inf')
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
(mod, MOD) = (1000000007, 998244353)
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

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()
(remain, m) = get_ints()
days = 0
while True:
	if remain > 0:
		remain -= 1
		days += 1
		if days % m == 0:
			remain += 1
	else:
		break
print(days)


l = list(map(int, input().split()))
(n, m) = (l[0], l[1])
socks = n // m
e = n + 1
c = n
while socks > 0:
	if e % m == 0:
		socks += 1
	socks -= 1
	c += 1
	e += 1
print(c)


(x, y) = list(map(int, input().split()))
if y > x:
	print(x)
elif x == y:
	print(x + 1)
else:
	x = [x for x in range(x)]
	counter = 0
	for t in x:
		counter += 1
		if counter == y:
			x.append(1)
			counter = 0
	print(len(x))


(n, m) = map(int, input().split())
(s, q) = (0, 0)
i = 1
for i in range(1, n + 1):
	s += 1
	if i % m == 0:
		q += 1
while q != 0:
	i += 1
	s += 1
	q -= 1
	if s % m == 0:
		q += 1
print(s)


import math
(n, m) = [int(s) for s in input().split(' ')]
d = 1
while n > 0:
	n -= 1
	if d % m == 0 and d > 0:
		n += 1
	d += 1
print(d - 1)


try:
	(n, m) = map(int, input().split())
	c = 0
	while n != 0:
		n -= 1
		c += 1
		if c % m == 0:
			n += 1
	print(c)
except EOFError:
	pass


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


x = input()
x = x.split()
a = int(x[0])
b = int(x[1])
res = 0
for i in range(1, a + 1):
	if b * i <= a:
		res += 1
	if (a + res) % b == 0:
		res += 1
print(res + a)


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


n = list(map(int, input().split()))
t = 0
count = 1
while t == 0:
	if n[1] * count <= n[0]:
		count += 1
		n[0] += 1
	else:
		break
print(n[0])


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


(n, m) = map(int, input().split())
ans = 0
buy = 0
canbuy = n
while canbuy > 0:
	ans += canbuy
	canbuy = ans // m - buy
	buy += canbuy
print(ans)


(n, m) = map(int, input().split())
MD = 1
for i in range(0, 101):
	if n >= MD * m:
		n += 1
		MD += 1
	else:
		break
print(n)


import sys
if False:
	input = open('socks.txt', 'r')
else:
	input = sys.stdin
ints = input.readline().split()
n = int(ints[0])
m = int(ints[1])
days = 0
while n != 0:
	days = days + 1
	n = n - 1
	if days % m == 0:
		n = n + 1
print(days)


(n, m) = map(int, input().split())
days = -1
for a in range(n * m):
	if n:
		if a % m != 0:
			n -= 1
		days += 1
	else:
		break
print(days)


nm = input().split(' ')
s = int(nm[0])
(c, i) = (0, int(nm[1]))
while i <= int(nm[0]):
	i += int(nm[1])
	c += 1
s += c
while s >= i:
	s += 1
	i += int(nm[1])
print(s)


from sys import stdin, stdout
(n, m) = [int(x) for x in stdin.read().rstrip().split()]
n -= 1
m -= 1
result = n // m + n + 1
print(result)


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


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


l = input()
l = l.split(' ')
n = int(l[0])
m = int(l[1])
c = 0
for i in range(1, 200):
	c += 1
	if i % m == 0:
		n += 1
	if i == n:
		break
print(c)


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


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


s = str(input()).split()
n = int(s[0])
m = int(s[1])
d = 0
while d != n:
	d += 1
	if d % m == 0:
		n += 1
print(d)


data = input()
data = data.split()
(n, m) = [int(x) for x in data]
i = 1
while True:
	if i % m == 0:
		n += 1
	elif i == n:
		break
	i += 1
print(i)


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


def bin(n, b):
	(l, r) = (n - 1, 2 * n)
	while l + 1 < r:
		m = (l + r) // 2
		if m > (m - 1) // b + n:
			r = m
		else:
			l = m
	return l
(n, m) = [int(x) for x in input().split()]
print(bin(n, m))


(n, m) = map(int, input().split())
count = 0
for i in range(1, n):
	x = m * i
	if x <= n + count:
		count = count + 1
	else:
		break
print(count + n)


(n, m) = map(int, input().split())
num = n
for i in range(200):
	num -= 1
	if num == 0 and (i + 1) % m != 0:
		print(i + 1)
		break
	elif (i + 1) % m == 0:
		num += 1


def day_num():
	inp = input().split(' ')
	n = int(inp[0])
	m = int(inp[1])
	ind = 1
	while 1:
		if n == 0:
			break
		n -= 1
		if ind % m == 0:
			n += 1
		ind += 1
	return ind - 1
print(day_num())


(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)


(n, m) = map(int, input().split())
if n < m:
	print(n)
elif n == m:
	print(n + 1)
else:
	k = n
	i = 1
	while k > 0:
		if i % m != 0:
			k -= 1
		i += 1
	print(i - 1)


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


import sys
(n, m) = map(int, sys.stdin.readline().split())
d = 0
while n > 0:
	d += 1
	n -= 1
	if d % m == 0:
		n += 1
print(d)


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


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


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


(s, p) = map(int, input().split())
increament = s // p
n = s + increament
remainder = n // p - increament
while remainder:
	n += remainder
	increament += remainder
	remainder = n // p - increament
print(n)


(a, b) = map(int, input().split(' '))
l = [1, 0]
k = 0
while l[-1] != l[-2]:
	k = k + a
	k = k // b
	l.append(k)
print(k + a)


(x, y) = map(int, input().split())

def F(x, y):
	r = x
	while x >= y:
		t = int(x % y)
		x = int(x / y)
		r = r + x
		x = x + t
	return r
print(F(x, y))


(a, b) = map(int, input().split())
if 1 <= a <= 100 and 2 <= b <= 100:
	c = (a * b - 1) // (b - 1)
	print(c)
else:
	print('error')


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


def noski(n, m):
	if n + n // m - m < m:
		return n + n // m
	return n + (n - 1) // (m - 1)
(N, M) = [int(i) for i in input().split()]
print(noski(N, M))


(n, m) = map(int, input().split())
t = n
for i in range(7):
	t += n // m
	n = n % m + n // m
print(t)


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


socks = list(map(int, input().split()))
days = socks[0] + socks[0] // socks[1]
socks[0] = socks[0] // socks[1] + socks[0] % socks[1]
while socks[0] >= socks[1]:
	days += socks[0] // socks[1]
	socks[0] = socks[0] // socks[1] + socks[0] % socks[1]
print(days)


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


(a, b) = map(int, input().split())
for i in range(1, 101):
	if b * i <= a:
		a += 1
	else:
		break
print(a)


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


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


(n, m) = input().split()
n = int(n)
m = int(m)
c = 0
while c // m + n != c:
	c = c + 1
print(c)


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


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())))


try:
	(n, m) = list(map(int, input().split()))
	sum = n
	while 1:
		a = n // m
		b = a + n % m
		n = b
		sum += a
		if b < m:
			break
	print(sum)
except:
	pass


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


(n, m) = list(map(int, input().split()))
x = 10000
while True:
	x -= 1
	if x == n + (x - 1) // m:
		break
print(x)


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

def facts(x1, x2):
	val = x1 % x2 + x1 // x2
	if x1 < x2:
		return x1
	else:
		x1 = x1 + x1 // x2
	while 1:
		if val >= x2:
			x1 = x1 + val // x2
			val = val // x2 + val % x2
		else:
			break
	return x1
f = facts(a, b)
print(f)


def main():
	(n, m) = map(int, input().split(' '))
	d = 0
	while n > 0:
		if d % m == 0:
			n += 1
		d += 1
		n -= 1
	return d - 1
print(main())


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


(n, m) = map(int, input().split())
x = n
day = 0
for i in range(1, 1000000):
	if x > 0:
		if i % m != 0:
			x -= 1
	elif x == 0:
		day = i - 1
		break
print(day)


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


socks = input()
socks = socks.split(' ')
num = int(socks[0])
new = int(socks[1])
count = 0
interval = 0
while num > 0:
	interval += 1
	count += 1
	num -= 1
	if interval == new:
		interval = 0
		num += 1
print(count)


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


z = list(map(int, input().split()))
count = 1
while z[0] > 0:
	if count % z[1] == 0:
		count += 1
		continue
	else:
		z[0] -= 1
		count += 1
print(count - 1)


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


(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)


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)]
(n, m) = sp()
answer = 0
i = 1
while n > 0:
	answer += 1
	if i % m == 0:
		n += 1
	n -= 1
	i += 1
print(answer)


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


def solve(n, m):
	extradays = (n - 1) // (m - 1)
	return n + extradays
(n, m) = map(int, input().split(' '))
print(solve(n, m))


(sock, mom) = [int(s) for s in input().split()]
m = 0
while sock != 0:
	sock -= 1
	m += 1
	if m % mom == 0:
		sock += 1
print(m)


nm = list(map(int, input().split()))
n = int(nm[0])
m = int(nm[1])
days = 0
tempm = m
while n > 0:
	days += 1
	n -= 1
	tempm -= 1
	if tempm == 0:
		n += 1
		tempm = m
print(days)


(n, m) = [int(x) for x in input().split()]
number_of_days = n
while n >= m:
	rem = n % m
	n -= rem
	div = n // m
	number_of_days += div
	n = div + rem
print(number_of_days)


(a, b) = input().split()
a = int(a, 10)
b = int(b, 10)
k = 0

def f(a, b, k):
	if a == 0:
		return 0
	else:
		a = a + k
		r = int(a / b)
		k = a % b
		return r + f(r, b, k)
l = f(a, b, k)
print(a + l)


from math import *
from copy import *
from string import *
from random import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
import math

def bin(l, r, ll, val):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		if ll[mid] == val:
			return mid
		elif ll[mid] > val:
			return bin(l, mid - 1, ll, val)
		else:
			return bin(mid + 1, r, ll, val)

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	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
(n, m) = map(int, input().split(' '))
c = 0
c1 = 1
while n != 0:
	if c1 == m:
		c = c + 1
		c1 = 1
	else:
		c = c + 1
		c1 = c1 + 1
		n = n - 1
print(c)


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


firstrow = list(map(int, input().split()))
days = 0
while firstrow[0] > 0:
	firstrow[0] -= 1
	days += 1
	if days % firstrow[1] == 0:
		firstrow[0] += 1
print(days)


(n, m) = map(int, input().split())
x = []
for i in range(400):
	x.append(n - i + i // m)
print(x.index(0))


class State:

	def __init__(self, socks, lim):
		self._socks = socks
		self._day = 0
		self._lim = lim

	def evaluate(self):
		if self._socks <= 0:
			return False
		else:
			self._socks -= 1
		if self._day % self._lim == 0:
			self._socks += 1
		self._day += 1
		return True
(m, n) = map(int, input().split())
state = State(m, n)
while state.evaluate():
	pass
print(state._day - 1)


while True:
	try:
		(n, m) = list(map(int, input().split()))
		ans = n + (n - 1) // (m - 1)
		print(ans)
	except EOFError:
		break


(x, y) = [int(x) for x in input().split()]
ans = x
inc = x // y
ans += inc
inc += x % y
while inc >= y:
	d = inc // y
	ans += d
	inc = d + inc % y
print(ans)


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


lst = list(map(int, input().strip().split(' ')))
s = lst[0]
m = lst[1]
d = 1
while s > 0:
	if d % m != 0:
		s -= 1
		if s > 0:
			d += 1
	else:
		s = s
		if s > 0:
			d += 1
print(d)


(n, m) = map(int, input().split())
d = n
r = 2
while r >= 1:
	r = n // m
	d += r
	n = r + n % m
print(d)


(a, b) = map(int, input().split())
s = a
t = a // b
l = [a // b]
while t != 0:
	s += t
	t = s // b - l[-1]
	l.append(s // b)
print(s)


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


(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)


from math import floor
(n, m) = tuple(map(int, input().split()))
days = n
socks = 0
if m <= n:
	socks = int(floor(n / m))
day = n + 1
while socks > 0:
	socks -= 1
	days += 1
	if day % m == 0:
		socks += 1
	day += 1
print(days)


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


(cnt, b) = input().split()
cnt = int(cnt)
b = int(b)
cnt1 = 0
while cnt > 0:
	cnt -= 1
	cnt1 += 1
	if cnt1 % b == 0:
		cnt += 1
print(cnt1)


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


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


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


T_ON = 0
DEBUG_ON = 0
MOD = 998244353

def solve():
	(n, m) = read_ints()

	def dfs(s, k):
		delta = (s + k - 1) // m - (s - 1) // m
		if delta == 0:
			return s + k - 1
		return dfs(s + k, delta)
	print(dfs(1, n))

def main():
	T = read_int() if T_ON else 1
	for i in range(T):
		solve()

def dbg(*xargs):
	if DEBUG_ON:
		print(*xargs)
from collections import *
import os
import sys
from io import BytesIO, IOBase
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 read_int():
	return int(input())

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

def print_nums(nums):
	print(' '.join(map(str, nums)))

def YES():
	print('YES')

def Yes():
	print('Yes')

def NO():
	print('NO')

def No():
	print('No')

def fib(n):
	(a, b) = (0, 1)
	for _ in range(n):
		(a, b) = (b, a + b)
	return a

def fib_ns(n):
	assert n >= 1
	f = [0 for _ in range(n + 1)]
	f[0] = 0
	f[1] = 1
	for i in range(2, n + 1):
		f[i] = f[i - 1] + f[i - 2]
	return f

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

def xgcd(a, b):
	(x0, x1, y0, y1) = (0, 1, 1, 0)
	while a != 0:
		((q, a), b) = (divmod(b, a), a)
		(y0, y1) = (y1, y0 - q * y1)
		(x0, x1) = (x1, x0 - q * x1)
	return (b, x0, y0)

def modinv(a, m):
	(g, x, _) = xgcd(a, m)
	if g != 1:
		raise Exception('gcd(a, m) != 1')
	return x % m

def mod_add(x, y):
	x += y
	while x >= MOD:
		x -= MOD
	while x < 0:
		x += MOD
	return x

def mod_mul(x, y):
	return x * y % MOD

def mod_pow(x, y):
	if y == 0:
		return 1
	if y % 2:
		return mod_mul(x, mod_pow(x, y - 1))
	p = mod_pow(x, y // 2)
	return mod_mul(p, p)

def mod_inv(y):
	return mod_pow(y, MOD - 2)

def mod_div(x, y):
	return mod_mul(x, mod_inv(y))

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

def gen_primes(n):
	P = [True for _ in range(n + 1)]
	P[0] = P[1] = False
	for i in range(int(n ** 0.5) + 1):
		if P[i]:
			for j in range(2 * i, n + 1, i):
				P[j] = False
	return P
main()


l = list(map(int, input().split(' ')))
stock = l[0]
m = l[1]
globalvar = 0
countm = 1
while stock > 0:
	globalvar += 1
	if countm * m == globalvar:
		countm += 1
		stock += 1
	stock -= 1
print(globalvar)


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


(vsego, period) = map(int, input().split())
den = 0
period1 = period
while vsego > 0:
	den = den + 1
	vsego = vsego - 1
	if den == period1:
		period1 = period1 + period
		vsego = vsego + 1
print(den)


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


(n, m) = [int(x) for x in input().split()]
num = n
day = 0
while num != 0:
	num -= 1
	day += 1
	if day % m == 0:
		num += 1
print(day)


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


import math
import sys
import cmath
import string
import bisect
from itertools import combinations, permutations
from queue import Queue, LifoQueue, PriorityQueue
from collections import deque, Counter
(n, m) = list(map(int, input().split()))
i = 1
while n > 0:
	n -= 1
	if i % m == 0:
		n += 1
	i += 1
print(i - 1)


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


str1 = input()
L = str1.split(' ')
socks = int(L[0])
secialday = int(L[1])
i = 0
while socks > 0:
	i += 1
	socks -= 1
	if i % secialday == 0:
		socks += 1
print(i)


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


def sock_days(n, m):
	if n == m:
		return n + 1
	elif m > n:
		return n
	else:
		x = n
		rem = n // m
		count = 0
		while x - m + 1 > 0:
			count += 1
			x = x - m + 1
		return n + count
(n, m) = map(int, input().split())
days = sock_days(n, m)
print(days)


def main():
	[n, m] = [int(_) for _ in input().split()]
	n_days = 0
	days_remained = 0
	while n > 0:
		new_days = n
		n = (days_remained + new_days) // m
		days_remained = (days_remained + new_days) % m
		n_days += new_days
	print(n_days)
main()


(n, m) = map(int, input().split())
x = 1
k = 0
while n + k != 0:
	n = n - 1
	k = x // m
	x += 1
print(x - 1)


(n, m) = input().split()
(n, m) = (int(n), int(m))
soma = 0
i = 0
while i < n:
	soma += 1
	if (i + 1) % m == 0:
		n += 1
	i += 1
print(soma)


import time
(n, m) = tuple(map(int, input().split()))
days = n
new_days = n // m
while new_days != 0:
	days += new_days
	new_days = days // m - n // m
	n = days
print(days)


mm = list(input().split())
from math import floor
n = int(mm[0])
m = int(mm[1])
sm = n
k = floor(n / m)
while k:
	t = floor((n + k) / m)
	if t == k:
		sm = n + k
		break
	else:
		k = t
print(sm)


(n, m) = map(int, input().split())
aux = [1 for i in range(n + 1)]
ans = 0
i = 1
while i < len(aux):
	if i % m == 0:
		aux.append(1)
	ans += 1
	i += 1
print(ans)


(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)


__author__ = 'Gamoool'
import sys
(n, m) = map(int, sys.stdin.readline().split())
u = n + (n - 1) // (m - 1)
print(u)


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


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


d = [int(x) for x in input().split(' ')]
i = d[0]
days = 1
while True:
	if i == 0:
		break
	i -= 1
	if days % d[1] == 0:
		i += 1
	days += 1
print(days - 1)


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


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


(hs, bsd) = map(int, input().split())
tillwhichday = hs
stock = 0
for i in range(1, hs + 1):
	if i % bsd == 0:
		stock += 1
while stock > 0:
	tillwhichday += 1
	if tillwhichday % bsd == 0:
		stock += 1
	stock -= 1
print(tillwhichday)


def vasya():
	(a, b) = map(int, input().split())
	sum_1 = a
	sum_2 = a
	i = 1
	while sum_1 > 0:
		sum_1 -= 1
		if i % b == 0:
			sum_1 += 1
			sum_2 += 1
		i += 1
	print(sum_2)
vasya()


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


(x, y) = map(int, input().split())
n = -1
e = 0
i = 0
if 1 <= x <= 100 and 2 <= y <= 200:
	while x >= 0:
		if i - y == 0:
			i = 0
			e += 1
		x = x - 1 + e
		e = 0
		i += 1
		n += 1
print(n)


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


import math
arr = input().split(' ')
n = int(arr[0])
m = int(arr[1])
prev_total = n
prev_ratio = math.floor(n / m)
total = n + math.floor(n / m)
ratio = math.floor(total / m)
while ratio != prev_ratio:
	total = total + ratio - prev_ratio
	prev_ratio = ratio
	ratio = math.floor(total / m)
print(int(total))


(n, m) = [int(x) for x in input().split()]
d = 1
while n:
	n -= 1
	if d % m == 0:
		n += 1
	if not n:
		break
	d += 1
print(d)


(x, y) = map(int, input().split())
i = 1
while x != 0:
	if i % y == 0:
		i += 1
	elif x == 1:
		x -= 1
	else:
		i += 1
		x -= 1
print(i)


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


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


(n, m) = input().split(' ')
n = int(n)
m = int(m)
d = 0
i = 1
while n != 0:
	d += 1
	n -= 1
	if d == i * m:
		n += 1
		i += 1
print(d)


(n, m) = map(int, input().split())
s = 0
s += n
while n >= m:
	r = int(n / m)
	s += r
	p = n % m
	g = int((p + r) / m)
	s += g
	y = (p + r) % m
	n = y + g
print(s)


(n, m) = [int(i) for i in input().split()]
count = 0
value = 0
k = n
while k:
	value = value + m
	if k >= value:
		count = count + 1
		k = k + 1
	else:
		break
if n == m:
	print(n + 1)
elif n > m:
	print(k)
else:
	print(n)


(n, m) = list(map(int, input().split()))
(start, stop) = (1, n)
if n < m:
	print(n)
else:
	while start <= stop:
		start += m
		stop += 1
	print(stop - 1 if start > stop else stop)


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


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


(n, m) = map(int, input().split())
ans = 0
l = [i for i in range(1, n + 1)]
c = n + 1
x = 0
i = 0
while i < n + x:
	if l[i] % m == 0:
		l.append(c)
		c += 1
		x += 1
	i += 1
if l[len(l) - 1] % m == 0:
	print(len(l) + 1)
else:
	print(len(l))


(n, m) = map(int, input().split())
a = n
for i in range(1, 300):
	if (i - 1) % m == 0 and i != 1:
		a += 1
	a -= 1
	if a < 0:
		print(i - 1)
		break


(n, m) = [int(x) for x in input().split(' ')]
day = 1
while True:
	n -= 1
	if day % m == 0:
		n += 1
	if n == 0:
		break
	else:
		day += 1
print(day)


import sys
import math
(n, m) = [int(x) for x in sys.stdin.readline().split()]
i = 0
res = 0
while i < n:
	res += 1
	i += 1
	if i % m == 0:
		n += 1
print(res)


numbers = input()
numbers = list(map(int, numbers.split()))
import math
socks = numbers[0]
days = numbers[1]
newSocks = 0
answer = 0
if socks < days:
	print(socks)
else:
	while socks > 1:
		if socks % days == 0:
			answer += socks
			socks = socks // days
		elif socks < days:
			break
		else:
			newSocks = math.floor(socks / days)
			answer += newSocks * days
			socks = newSocks + socks % days
	print(answer + socks)


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


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


(n, k) = map(int, input().split())
l = 1
while True:
	if l >= k and l % k == 0:
		n += 1
	n -= 1
	if n == 0:
		print(l)
		exit()
	l += 1


a = list(map(int, input().split()))
n = a[0]
m = a[1]
s = n
i = 1
while s > 0:
	s -= 1
	if i % m == 0:
		s += 1
	i += 1
print(i - 1)


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)


(n, m) = (int(i) for i in input().split())
days = n
exdays = (n - 1) // (m - 1)
print(days + exdays)


(n, m) = (int(i) for i in input().split())
l = [n]
while l[-1] > 0:
	l.append(sum(l) // m - sum(l[:-1]) // m)
print(sum(l))


__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


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


TN = 1

def solution():
	(n, m) = map(int, input().split())
	ans = n + int((n - 1) / (m - 1))
	print(ans)
while TN != 0:
	solution()
	TN -= 1


a = input().split(' ')
n = int(a[0])
m = int(a[1])
ans = 0
d = 1
while n > 0:
	ans += 1
	n -= 1
	n += d % m == 0
	d += 1
print(ans)


(num_socks, new_socks) = map(int, input().split())
passed_days = 0
counter = 0
while num_socks != 0:
	num_socks -= 1
	counter += 1
	if counter % new_socks == 0:
		num_socks += 1
	passed_days += 1
print(passed_days)


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		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 = self.os.read(self._fd, max(self.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 = self.os.read(self._fd, max(self.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:
			self.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')
import collections as col
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7

def solve():
	(N, M) = getInts()
	x = 1
	while True:
		if N - x + x // M == 0:
			return x
		x += 1
print(solve())


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


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


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


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


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


L = input()
L = L.split()
n = int(L[0])
m = int(L[1])
Dias = n
while n >= m:
	DA = n // m
	n = DA + n % m
	Dias += DA
print(Dias)


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


def how_much_day(n, m):
	day = 0
	while n >= 1:
		day += 1
		n -= 1
		if day % m == 0:
			n += 1
	return day

def main():
	(n, m) = list(map(int, input().split()))
	print(how_much_day(n, m))
main()


l = list(map(int, input().split()))
if l[0] >= l[1]:
	i = 1
	c = 0
	while l[0] > 0:
		if l[1] == i:
			l[0] += 1
			i = 0
		l[0] -= 1
		c += 1
		i += 1
	print(c)
else:
	print(l[0])


lst = [int(x) for x in input().split()]
(socks_days, purchase_socks) = (lst[0], lst[1])
d_count = socks_days
while socks_days != 1:
	if socks_days < purchase_socks:
		print(d_count)
		break
	d_count = d_count + socks_days // purchase_socks
	socks_days = socks_days % purchase_socks + socks_days // purchase_socks
else:
	print(d_count)


(n, m) = [int(x) for x in input().split()]
t = n
k = 1
sum = 0
while True:
	k = int(n / m)
	n = k + n % m
	sum += k
	if k == 0:
		break
print(sum + t)


l = list(map(int, input().split()))
(n, m) = (l[0], l[1])
print(n + int((n - 1) / (m - 1)))


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)


(N, M) = map(int, input().split())
SUM = 0
while N != 0:
	SUM += 1
	N -= 1
	if SUM % M == 0:
		N += 1
print(SUM)


(lst, n, v) = (list(map(int, input().split(' '))), 0, 0)
if lst[0] == 1 and lst[1] == 1:
	print(2)
else:
	while lst[0] > v:
		n += 1
		if n == lst[1]:
			lst[0] += 1
			n = 0
		v += 1
	print(lst[0])


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


l = list(map(int, input().split()))
print(l[0] + (l[0] - 1) // (l[1] - 1))


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


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


(n, m) = map(int, input().split())
t = n // (m - 1)
s = n % (m - 1)
if s == 0:
	days = t * m + s - 1
else:
	days = t * m + s
print(days)


import sys
(n, m) = map(int, sys.stdin.readline().split())
day = 0
mom = 0
while n > 0:
	day += n
	mom += n
	if mom >= m:
		n = int(mom / m)
		mom -= n * m
	else:
		break
print(day)


import sys
_inputs = [x for x in '10 2\n'.split('\n') if bool(x)]
if '--debug' not in sys.argv:
	_inputs = [input() for _ in range(len(_inputs))]
(n, m) = [int(x) for x in _inputs[0].split()]
result = 0
while n > 0:
	result += 1
	n -= 1
	if result % m == 0:
		n += 1
print(result)


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


s = input()
s = s.split()
n = int(s[0])
m = int(s[1])
ans = 0
for i in range(1, 1000):
	if n > 0:
		ans += 1
		n -= 1
	else:
		break
	if i % m == 0:
		n += 1
print(ans)


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


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


from fractions import Fraction
(a, b) = map(int, input().split())
count = 0
while a >= 1:
	count += 1
	a = a - 1 + Fraction(f'1/{b}')
print(count)


import sys

def main():
	(m, n) = [int(x) for x in sys.stdin.readline().strip().split()]
	day = 0
	while m > 0:
		day += 1
		m -= 1
		if day % n is 0:
			m += 1
	print(day)
main()


(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())
x = n + n // m
while x < n + x // m:
	x += 1
print(x)


import math
(n, m) = [int(x) for x in input().split()]
nb_days = 0
while n > 0:
	nb_days += 1
	n -= 1
	if nb_days % m == 0:
		n += 1
print(nb_days)


b = [int(x) for x in input().split()]
n = b[0]
m = b[1]
br = 0
while True:
	if br > 1 and br % m == 0:
		n += 1
	if n > 0:
		br += 1
		n -= 1
	else:
		print(br)
		break


(n, d) = map(int, input().split())
day = 0
l = 0
while n != 0:
	n -= 1
	day += 1
	l += 1
	if day == d:
		n += 1
		day = 0
print(l)


(n, m) = map(int, input().split())
for day in range(n, 2 * n + 1):
	if n + (day - 1) // m < day:
		print(day - 1)
		break


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


(n, m) = map(int, input().split())
socks = n
r = 0
t = n
while t >= 1:
	t = t + r
	socks = socks + t // m
	r = t % m
	t = t // m
print(socks)


(n, m) = [int(_) for _ in input().split()]
ans = 0
r = 0
while True:
	if n == 0:
		break
	ans += n
	nn = (n + r) // m
	r = (n + r) % m
	n = nn
print(ans)


test = '9 3'
(n, m) = map(int, input().split())
d = 1
while n > 0:
	n -= 1
	if d % m == 0:
		n += 1
	d += 1
print(d - 1)


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)


i = 1
l = list(map(int, input().split()))
m = l[1]
p = l[0]
x = i * m
while x <= p:
	p += 1
	i += 1
	x = i * m
print(p)


def socks():
	(n, m) = input().split()
	(n, m) = (int(n), int(m))
	day = 1
	x = 1
	while n > 0:
		n -= 1
		if day == x * m:
			n += 1
			x += 1
		day += 1
	print(day - 1)
socks()


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


(n, m) = input().split()
n = int(n)
m = int(m)
counts = 1
sum = n
while True:
	if counts % m == 0:
		sum += 1
	sum -= 1
	counts += 1
	if sum == 0:
		break
print(counts - 1)
pass


def vasyaAndSocks(n, m):
	cnt = n
	i = m
	while i <= n:
		n += 1
		i = i + m
	return n
(n, m) = map(int, input().strip().split())
print(vasyaAndSocks(n, m))


k = list(map(int, input().split()))
i = 1
n = k[0]
while k[1] * i <= n:
	n = n + 1
	i += 1
print(n)


(p, q) = map(int, input().split())
z = 1
while z <= p:
	if z % q == 0:
		p += 1
	z += 1
print(p)


a = input()
a = a.split()
a1 = int(a[0])
a2 = int(a[1])
suma = a1
while a1 >= a2:
	c = a1 // a2
	suma = suma + c
	a1 = a1 % a2 + c
print(suma)


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


def main():
	(initial, recur) = tuple(map(int, input().split()))
	print(initial // (recur - 1) * recur + (initial % (recur - 1) or -1))
main()


import math
(n, m) = input().split()
n = int(n)
m = int(m)
print((n * m - 1) // (m - 1))


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


nm = input().split()
n = int(nm[0])
m = int(nm[1])
d = 0
while n != 0:
	n -= 1
	d += 1
	if d % m == 0 and d != 0:
		n += 1
print(d)


values = input().split()
(socks, gap) = (int(values[0]), int(values[1]))
days = 0
while socks:
	socks -= 1
	days += 1
	if days % gap == 0:
		socks += 1
print(days)


(a, b) = list(map(int, input().split()))
sd = a + a // (b - 1)
if a % (b - 1) == 0:
	sd -= 1
print(sd)


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


import sys
(n, m) = sys.stdin.readline().strip().split(' ')
(n, m) = (int(n), int(m))
p = 0
while n > 0:
	p = p + 1
	i = 0
	if p % m == 0:
		i = 1
	n = n - 1 + i
print(p)


(a, d) = map(int, input().split())
a1 = 1
d2 = 0
i = 0
while a + d2 // d > 0:
	a = a - a1
	d2 = d2 + 1
	i += 1
print(i)


n = [int(i) for i in input().split()]
i = 0
while n[0] > 0:
	i += 1
	n[0] -= 1
	if i % n[1] == 0:
		n[0] += 1
print(str(i))


(n, m) = [int(x) for x in input().split()]
x = 1

def socks(n):
	global x
	if n > 0:
		if x % m > 0:
			n = n - 1
			x = x + 1
			socks(n)
		else:
			x = x + 1
			socks(n)
	elif n == 0:
		print(x - 1)
socks(n)


nm = [int(i) for i in input().split()]
n = nm[0]
m = nm[1]
days = 0
for i in range(1, 200):
	if n == 0:
		break
	if i % m == 0:
		days += 1
	elif i % m != 0:
		days += 1
		n -= 1
print(days)


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())
x = n + n // m
t = n // m + n % m
while t >= m:
	x += t // m
	t = t // m + t % m
print(x)


data = list(map(int, input().split()))
count = data[0]
days_per_buy = data[1]
days_after_buy = 0
days = 0
while count > 0:
	count -= 1
	days_after_buy += 1
	if days_per_buy == days_after_buy:
		days_after_buy = 0
		count += 1
	days += 1
print(days)


(i, j) = input().split()
i = int(i)
j = int(j)
counter = 0
x = 1
while True:
	i -= 1
	counter += 1
	if x % j == 0:
		i += 1
	if i < 1:
		break
	x += 1
print(counter)


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


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


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


(n, m) = map(int, input().split())
a = 0
for x in range((n * m - 1 - m) // (m - 1) + 1, (n * m - 1) // (m - 1) + 1):
	if n + (x - 1) // m == x:
		a = max(a, x)
print(a)


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, m) = map(int, input().split())
nos = n
s = 0
while nos != 0:
	nos -= 1
	s += 1
	if s % m == 0:
		nos += 1
print(s)


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)


(n, m) = list(map(int, input().split(' ')))
left_socks = 0
days = n
i = 1
while i * m <= days:
	left_socks += 1
	i += 1
	days += 1
print(days)


(m, n) = map(int, input().split())
i = 1
d = [0] * 1000001
y = 0
while i >= 0:
	y = y + m % n
	d[i] = m
	m = int(m / n) + int(y / n)
	y = y % n
	if d[i] <= 0:
		break
	i += 1
print(sum(d))


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


arr = [int(i) for i in input().split(' ')]
(n, m, day) = (arr[0], arr[1], 0)
while n > 0:
	day += 1
	n -= 1
	if day % m == 0:
		n += 1
print(day)


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


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


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


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
(n, m) = nextints(2)
i = 0
while n > 0:
	i += 1
	n -= 1
	if i % m == 0:
		n += 1
print(i)


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


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


(n, m) = list(map(int, input().split()))
k = n
x = n
j = 0
while k // m - j != 0:
	x += k // m - j
	j = k // m
	k = x
print(x)


(n, m) = input().split(' ')
n = int(n)
m = int(m)
x = 0
while True:
	if x - x // m == n:
		print(int(x))
		break
	else:
		x += 1


(n, m) = list(map(int, input().split()))
print(list((x for x in list(range(10000)) if x == n + x // m))[0])


emon = input().split()
x = int(emon[0])
y = int(emon[1])
a = 0
b = 0
sock = 0
if x == y:
	print(x + 1)
	b += 1
elif y > x:
	print(x)
	b += 1
else:
	while 1:
		a = a + 1
		x = x + 1
		sock = y * a
		if sock >= x:
			break
if b == 0:
	print(x - 1)


def solve(n, m):
	res = n + n // (m - 1)
	if n % (m - 1) == 0:
		res -= 1
	return res
(n, m) = map(int, input().split(' '))
print(solve(n, m))


(x, y) = input().split()
numSocks = int(x)
daysPerBuy = int(y)
dayCount = 0
while True:
	numSocks -= 1
	dayCount += 1
	if numSocks < 0:
		break
	if dayCount % daysPerBuy == 0:
		numSocks += 1
print(dayCount - 1)


import math
raw_input = input().split(' ')
socks = int(raw_input[0])
mom = int(raw_input[1])
print(socks + math.floor((socks - 1) / (mom - 1)))


s = input().split(' ')
(n, m) = [int(s[i]) for i in range(0, 2)]
l = n
r = 0
while l > 0:
	r += 1
	if r % m == 0 and r >= m:
		l += 1
	l -= 1
print(r)


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


import sys
from copy import copy
(n, m) = map(int, input().split())
t = 1
while 1:
	n -= 1
	if t % m == 0:
		n += 1
	if n > 0:
		t += 1
	else:
		break
print(t)


(n, t) = [int(x) for x in input().split()]
d = 0
k = 1
top = n
while d - k != 0:
	k = int(top / t)
	top = top + k - d
	d = int(top / t)
	top = top + d - k
print(top)


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


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


(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))


def ras(m, n):
	k = 0
	if m - n < 0:
		return m
	elif m - n == 0:
		return m + 1
	else:
		while True:
			m = m - n + 1
			k = k + n
			if m - n < 0:
				k = k + m
				return k
(m, n) = map(int, input().split())
r = ras(m, n)
print(r)


from sys import stdin
(n, m) = (int(x) for x in stdin.readline().strip().split(' '))
result = 0
while n != 0:
	result += 1
	if result % m != 0:
		n -= 1
print(result)


n = list(map(int, input().rstrip().split()))
numsock = n[0]
m = n[1]
day = 0
flag = 0
while numsock > 0:
	day += 1
	numsock -= 1
	if flag == 1:
		numsock += 1
		flag = 0
	if day % m == 0:
		flag = 1
if day % m == 0:
	print(day + 1)
else:
	print(day)


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


(N, M) = map(int, input().split())
cnt = 0
while N != 0:
	N -= 1
	cnt += 1
	if cnt % M == 0:
		N += 1
print(cnt)


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


(n, k) = (int(i) for i in input().split())
s = 0
d = 0
while n > 0:
	s += 1
	n -= 1
	d += 1
	if d % k == 0:
		n += 1
		d = 0
print(s)


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


import sys
from sys import stdin, stdout
import math
import random
import heapq
from collections import Counter
from functools import lru_cache
try:
	for _ in range(1):
		(n, m) = map(int, input().split())
		days = 0
		while n > 0:
			n -= 1
			days += 1
			if days % m == 0:
				n += 1
		print(days)
except EOFError as e:
	print(e)


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


inputLine = input()
myList = inputLine.split(' ')
initial = int(myList[0])
period = int(myList[1])
day = 0
while initial != 0:
	initial -= 1
	day += 1
	if day % period == 0:
		initial += 1
print(day)


(n, m) = map(int, input().split())
dp = n // m
ndp = 0
while dp - ndp > 0:
	n += dp - ndp
	ndp = dp
	dp = n // m
print(n)


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


ln = input().split(' ')
n = int(ln[0])
m = int(ln[1])
res = n
k = int(n / m)
p = res - k * m
while k > 0:
	res = res + k
	f = k + p
	k = int(f / m)
	p = f - k * m
print(res)


N = list(map(int, input().split()))
N = int(N[0] + (N[0] - 1) / (N[1] - 1))
print(N)


import sys
input = lambda : sys.stdin.readline().strip()
(n, m) = map(int, input().split())
d = n * m // (m - 1)
if not d % m:
	d -= 1
print(d)


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


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


foo = input().split(' ')
a = int(foo[0])
b = int(foo[1])
bar = a + a // (b - 1)
if a % (b - 1) == 0:
	bar -= 1
print(bar)


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


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


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


string = input('')
(num1, num2) = string.split(' ')
num2 = int(num2)
socksLeft = int(num1)
day = 1
while socksLeft != 0:
	if day % num2 == 0:
		socksLeft += 1
	socksLeft -= 1
	day += 1
print(day - 1)


(socks, bought) = map(int, input().split())
bonus = 0
cnt = 1
new = 0
days = 0
if socks >= bought:
	while socks >= days:
		days += 1
		new = bought * cnt
		if new == days:
			cnt += 1
			bonus += 1
		if socks >= days:
			socks += bonus
			bonus = 0
print(socks)


def get_numlist():
	list_in = list(input().split())
	list_out = []
	for k in list_in:
		list_out += [int(k)]
	return list_out

def main():
	list0 = get_numlist()
	a = list0[0]
	b = list0[1]
	day = 0
	freq = 0
	bull = True
	while bull:
		day += 1
		freq += 1
		if freq == b:
			freq = 0
		else:
			a -= 1
		if a == 0:
			bull = False
		else:
			continue
	print(day)
main()


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


import os
import sys
from io import BytesIO, IOBase
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))

def input():
	return sys.stdin.readline().rstrip('\r\n')
(n, m) = list(map(int, input().split(' ')))
left_socks = 0
days = n
i = 1
while i * m <= days:
	left_socks += 1
	i += 1
	days += 1
print(days)


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


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())
i = 1
s = 1
while l[0] > 0:
	l[0] -= 1
	if i == s * l[1]:
		s += 1
		l[0] += 1
	i += 1
print(i - 1)


(n, m) = input().split(' ')
n = int(n)
m = int(m)
days = 0
while n // m > 0:
	days = days + n // m * m
	n = n % m + n // m
print(days + n)


inp = input()
nums = inp.split(' ')
base = int(nums[0])
m = int(nums[1])
add = 0
n = base
i = 0
while i < base:
	if (i + 1) % m == 0:
		base = base + 1
	i = i + 1
print(i)


(n, m) = list(map(int, input().split()))
count = 0
while n >= m:
	r = n % m
	count += n - r
	added = (n - r) // m
	n = r + added
count += n
print(count)


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


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


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


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)


(x, y) = map(int, input().split())
check = x
t = x
result = 0
while x > 0:
	x = x // y
	check += x
ans = 0
for i in range(check):
	if (i + 1) % y == 0:
		ans = ans + 1
if (ans + t) % y == 0:
	print(ans + t + 1)
else:
	print(ans + t)


import math
(n, m) = map(int, input().split())
ans = math.ceil(n / (1 - 1 / m)) - 1
print(ans)


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)


(n, m) = [int(i) for i in input().split()]
count = 0
wait = 0
while True:
	if n == 0:
		break
	else:
		count += 1
		n -= 1
		wait += 1
	if wait == m:
		wait = 0
		n += 1
print(count)


(n, m) = map(float, input().split(' '))
days = 0
while n:
	days += 1
	if (days / m).is_integer():
		n += 1
	n -= 1
print(days)


(s, f) = map(int, input().split())
for i in range(1000):
	s -= 1
	if s == -1:
		break
	if (i + 1) % f == 0:
		s += 1
print(i)


import sys

def main():
	(n, m) = map(int, sys.stdin.readline().split())
	d = 0
	count = 0
	while n > 0:
		d += 1
		n -= 1
		if d % m == 0:
			n += 1
		count += 1
	sys.stdout.write(f'{count}')
main()


s = input()
n = int(s[:s.find(' ')])
m = int(s[s.find(' '):])
socks = n
i = 0
while socks > 0:
	i += 1
	socks -= 1
	if i % m == 0:
		socks += 1
print(i)


(n, m) = input('').split(' ')
(n, m) = (int(n), int(m))
(socks, count) = ([], 0)
for i in range(n):
	socks.append('s')
while socks:
	for i in range(len(socks)):
		if (count + 1) % m == 0:
			socks.append('s')
		count += 1
		socks.remove('s')
print(count)


from sys import stdin, stdout, stderr, setrecursionlimit
setrecursionlimit(100000)

def debug(*e):
	if not __debug__:
		print(*e, file=stderr)

def dd(*vals):
	import inspect, re
	frame = inspect.getframeinfo(inspect.stack()[1][0])
	vs = re.search('dd\\((.+)\\)', frame.code_context[0]).group(1).split(',')
	if vs:
		debug(','.join(('{0} = {1}'.format(vs[i], v) for (i, v) in enumerate(vals))))

def trace(f):

	def traced(*args, **kw):
		debug('calling {} with args {}, {}'.format(f.__name__, args, kw))
		return f(*args, **kw)
	return traced

def read():
	return stdin.readline().rstrip()

def readarr(sep=None, maxsplit=-1):
	return read().split(sep, maxsplit)

def readint():
	return int(read())

def readia(sep=None, maxsplit=-1):
	return [int(a) for a in readarr(sep, maxsplit)]

def write(*args, **kwargs):
	sep = kwargs.get('sep', ' ')
	end = kwargs.get('end', '\n')
	stdout.write(sep.join((str(a) for a in args)) + end)

def writea(arr, sep=' ', end='\n'):
	stdout.write(sep.join((str(a) for a in arr)) + end)
(n, m) = readia()
for t in range(1, 10000000):
	if t > n:
		write(t - 1)
		break
	if t % m == 0:
		n += 1


import math
import os
import random
import re
import sys
a = list(map(int, input().rstrip().split()))
days = 0
socks = a[0]
m = a[1]
while socks != 0:
	days = days + 1
	socks = socks - 1
	if days % m == 0:
		socks = socks + 1
print(days)


day = 0
A = list(map(int, input().split()))
socks = A[0]
m = A[1]
while socks > 0:
	day += 1
	socks = socks - 1
	if day % m == 0:
		socks += 1
print(day)


line = list(map(int, input().split()))
(n, m) = (line[0], line[1])
counter_day = 0
counter_m = 0
while n != 0:
	counter_m += 1
	if counter_m == m:
		n += 1
		counter_m = 0
	n -= 1
	counter_day += 1
print(counter_day)


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


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


(n, m) = input().split()
n = int(n)
m = int(m)
g = m
t = 0
while n > 0:
	t += 1
	n -= 1
	if t == m:
		n += 1
		m += g
print(t)


(n, m) = [int(a) for a in input().split()]
ans = 0
while n > 0:
	n -= 1
	ans += 1
	if ans % m == 0:
		n += 1
print(ans)


(n, m) = [int(x) for x in input().split()]
if m > n:
	t = n
elif m == n:
	t = n + 1
elif n % (m - 1) == 0:
	t = n // (m - 1) * m - 1
else:
	t = n // (m - 1) * m + n % (m - 1)
print(t)


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


l = list(map(int, input().split()))
s = l[0]
d = 1
while s > 0:
	s -= 1
	if d % l[1] == 0:
		s += 1
	d += 1
print(d - 1)


s = input().split()
x = int(s[0])
y = int(s[1])
for i in range(200):
	x = x - 1
	if (i + 1) % y == 0:
		x = x + 1
		if x == 1:
			print(i + 2)
			break
	elif x == 0:
		print(i + 1)
		break


(n, m) = map(int, input().split())
ans = n
prev = 0
cur = n
add = n // m
while add > 0:
	ans += add
	prev = cur
	cur = cur + add
	add = cur // m - prev // m
print(ans)


items = input().strip('\n\r\t ').split(' ')
n = int(items[0])
m = int(items[1])
socks = n
d = 1
while socks > 0:
	socks -= 1
	if d % m == 0:
		socks += 1
	d += 1
print(d - 1)


(n, m) = map(int, input().split())
cnt = 0
while n >= 0:
	cnt += 1
	n -= 1
	if n < 0:
		break
	elif cnt % m == 0:
		n += 1
	else:
		pass
print(cnt - 1)


__author__ = 'runekri3'
(socks, buy_frequency) = list(map(int, input().split()))
day = 0
while socks > 0:
	day += 1
	socks -= 1
	if day % buy_frequency == 0:
		socks += 1
print(day)


(N, M) = map(int, input().split())
sockshehas = N
days = 0
while sockshehas > 0:
	days += 1
	sockshehas -= 1
	if days % M == 0:
		sockshehas += 1
print(days)


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


(n, m) = tuple(map(int, input().split()))
res = n
if n < m:
	print(n)
else:
	while True:
		i = int(n / m)
		j = n % m
		res += i
		if n == 0 or n == 1 or n == i + j:
			break
		n = i + j
	print(res)


aa = input().split(' ')
n = int(aa[0])
d = int(aa[1])
ans = 0
while n >= d:
	ans += 1
	n -= d - 1
print(ans * d + n)


(n, m) = map(int, input().split())
li = []
li.append(n)
a = n
while a // m > 0:
	li.append(a // m)
	a = a % m + a // m
print(sum(li))


inputList = [int(x) for x in input().split()]
n = inputList[0]
m = inputList[1]

def socks(n, m):
	day = 0
	while n >= m:
		day += m
		n -= m
		n += 1
	return day + n
print(socks(n, m))


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


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


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


inputs = list(map(int, input().split(' ')))
initialSocks = inputs[0]
shopDay = inputs[1]
totalDays = initialSocks
prevCounter = 0
while totalDays // shopDay != prevCounter:
	if prevCounter == 0:
		prevCounter = totalDays // shopDay
		totalDays += prevCounter
	else:
		totalDays += 1
		prevCounter += 1
print(totalDays)


(n, m) = list(map(int, input().split()))
n1 = 0
while n - n1 + int(n1 / m):
	n1 = n1 + 1
print(n1)


from itertools import count
(n, m) = map(int, input().split())
buy = m
for i in count(1):
	if n == 0:
		print(i - 1)
		break
	n -= 1
	if i == buy:
		n += 1
		buy += m


(n, m) = [int(i) for i in input().split()]
k = n
p1 = 0
while True:
	p = k // m
	p = p - p1
	if p == 0:
		break
	k = k + p
	p1 = p1 + p
print(k)


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


lst = input().split()
n = int(lst[0])
m = int(lst[1])
count = 0
while True:
	count += 1
	n -= 1
	if n < 0:
		break
	if count % m == 0:
		n += 1
print(count - 1)


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


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


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


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