Anton has the integer x. He is interested what positive integer, which doesn't exceed x, has the maximum sum of digits.

Your task is to help Anton and to find the integer that interests him. If there are several such integers, determine the biggest of them. 


-----Input-----

The first line contains the positive integer x (1 ≤ x ≤ 10^18) — the integer which Anton has. 


-----Output-----

Print the positive integer which doesn't exceed x and has the maximum sum of digits. If there are several such integers, print the biggest of them. Printed integer must not contain leading zeros.


-----Examples-----
Input
100

Output
99

Input
48

Output
48

Input
521

Output
499

Source: codeforces | Difficulty: EASY
Tags: Mathematics

Implementation


Solutions:
x = int(input())
answer = [x]
for i in range(1, len(str(x))):
	answer.append(x - x % 10 ** i - 1)
answer.sort(key=lambda j: sum([int(i) for i in str(j)]), reverse=True)
print(answer[0])


def f(s):
	if len(s) == 1:
		return [ord(s[0]) - ord('0'), s]
	if s[0] == '0':
		return [f(s[1:])[0], '0' + f(s[1:])[1]]
	a = [f(s[1:])[0] + ord(s[0]) - ord('0'), s[0] + f(s[1:])[1]]
	b = [ord(s[0]) - ord('0') - 1 + 9 * (len(s) - 1), str(int(s[0]) - 1) + (len(s) - 1) * '9']
	if b > a:
		return b
	return a
n = input()
print(int(f(n)[1]))


m = input()
n = str(int(m[0]) - 1) + '9' * (len(m) - 1)
k = sum(list(map(int, m)))
p = sum(list(map(int, n)))
t = l = n
if len(m) == 1:
	t = m
elif len(m) > 1:
	l = str(int(n[0]) + 1) + str(int(n[1]) - 1) + n[2:]
	for i in range(1, len(n)):
		if int(l) > int(m):
			break
		t = l
		if i == len(n) - 1:
			l = l[0:-1] + str(int(l[-1]) + 1)
		else:
			l = l[0:i] + str(int(l[i]) + 1) + str(int(l[i + 1]) - 1) + l[i + 2:]
	if l <= m:
		t = l
print(int(t))


def main():

	def sum(x):
		res = 0
		while x > 0:
			res += x % 10
			x //= 10
		return res
	n = input()
	first = n[0]
	p = [1]
	for i in range(1, 20):
		p.append(p[-1] * 10)
	data = []
	for i in range(len(n)):
		if i > 0 and n[i] == '0':
			continue
		temp = n[:i] + str(max(0, int(n[i]) - 1)) + '9' * (len(n) - i - 1)
		data.append((sum(int(temp)), int(temp)))
	data.append((sum(int(n)), int(n)))
	data.sort(reverse=True)
	print(data[0][1])
	return

def __starting_point():
	main()
__starting_point()


import collections as col
import itertools as its
import sys
import operator
from copy import copy, deepcopy

class Solver:

	def __init__(self):
		pass

	def solve(self):
		xs = input()
		pxs = xs
		xs = list(map(int, xs))
		bpos = -1
		for i in range(1, len(xs)):
			if xs[i] != 9:
				bpos = i
				break
		if bpos != -1:
			xs[bpos - 1] -= 1
			for i in range(bpos, len(xs)):
				xs[i] = 9
		xs = ''.join(map(str, xs))
		if sum(map(int, pxs)) >= sum(map(int, xs)):
			xs = pxs
		print(int(xs))
s = Solver()
s.solve()


x = int(input())
if x < 10:
	print(x)
elif x == int(str(x)[0] + '9' * (len(str(x)) - 1)):
	print(x)
else:
	a = str(x)[0] + '9' * (len(str(x)) - 1)
	a = list(a)
	for i in range(len(a) - 1, -1, -1):
		k = a[i]
		a[i] = str(int(a[i]) - 1)
		if x >= int(''.join(a)):
			print(int(''.join(a)))
			break
		a[i] = k


def __starting_point():
	x = input()
	if int(x) < 10:
		print(x)
		return
	arr = [int(a) for a in list(x)]
	x_sum = sum(arr)
	i = len(arr) - 1
	answer = ''
	while i > 0:
		if arr[i] != 9 and arr[i] != 8:
			arr[i - 1] -= 1
			answer = '9' + answer
		else:
			change = False
			for j in range(i - 1, 0, -1):
				if arr[j] < 9:
					change = True
					break
			if arr[i] == 8 and change:
				answer = '9' + answer
				arr[i - 1] -= 1
			elif not change:
				answer = str(arr[i]) + answer
			else:
				answer = '9' + answer
		if i == 1 and arr[0] != 0:
			answer = str(arr[0]) + answer
		i -= 1
	answer = [int(a) for a in list(answer)]
	if x_sum == sum(answer):
		print(x)
	else:
		answer = [str(a) for a in answer]
		print(''.join(answer))
__starting_point()


n = int(input())

def sum_digits(n):
	if n < 10:
		return n
	s = 0
	while n:
		s += n % 10
		n //= 10
	return s
max_sum = sum_digits(n)
max_num = n
while str(n)[-1] != '9':
	n -= 1
if sum_digits(n) > max_sum or (sum_digits(n) == max_sum and n > max_num):
	max_sum = sum_digits(n)
	max_num = n
n_copy = n
for i in range(1, len(str(n)) - 1):
	n_copy -= 10 ** i * (int(str(n_copy)[-i - 1]) + 1)
	if sum_digits(n_copy) > max_sum or (sum_digits(n_copy) == max_sum and n_copy > max_num):
		max_sum = sum_digits(n_copy)
		max_num = n_copy
print(max_num)


def f(a):
	s = 0
	k = 0
	while a > 0:
		k += 1
		s += a % 10
		a //= 10
	return (s, k)
x = int(input())
(s_x, k) = f(x)
if k == 1:
	print(x)
	exit()
arr = []
for current_k in range(1, k):
	y = str(x // 10 ** current_k - 1) + '9' * current_k
	y = int(y.strip('0'))
	s_y = f(y)[0]
	if s_y > s_x:
		arr.append((y, s_y))
max_pair = max(arr, key=lambda x: x[1]) if len(arr) > 0 else (x, s_x)
if max_pair[1] > s_x:
	print(max_pair[0])
else:
	print(x)


def sum_n(n):
	l = len(n)
	summ = 0
	for i in range(l):
		summ += int(n[i])
	return summ

def transfer(x, i):
	x = list(x)
	x[i + 1] = '9'
	if x[i] != '0':
		x[i] = str(int(x[i]) - 1)
	else:
		j = i
		while j > 0 and int(x[j]) == 0:
			x[j] = '9'
			j -= 1
		x[j] = str(int(x[j]) - 1)
	if x[0] == '0':
		del x[0]
	return x
x = list(input())
max_cifr = sum_n(x)
maxnum = x
res = ''
for i in range(len(x) - 2, -1, -1):
	x = transfer(x, i)
	if max_cifr < sum_n(x):
		max_cifr = sum_n(x)
		maxnum = x
for i in range(len(maxnum)):
	res = res + maxnum[i]
print(res)


a = int(input())
if a // 10 == 0:
	print(a)
	return
k = 9
while k < a:
	k = k * 10 + 9
if k == a:
	print(k)
else:
	k //= 10
	k = int(str(a)[0] + str(k))
	i = len(str(k)) - 1
	z = k
	while z > a:
		z = int(str(k)[0:i] + str(int(str(k)[i]) - 1) + str(k)[i + 1:len(str(k))])
		i -= 1
	print(z)


n = int(input().strip())
s = []
while n > 0:
	s.append(n % 10)
	n //= 10
s = s[::-1]
n = len(s)
ans = 0
best = -1
for i in range(n):
	res = sum(s[:i + 1]) - 1 + 9 * (n - i - 1)
	if res >= ans:
		ans = res
		best = i

def get(s, pos):
	ans = 0
	for i in range(len(s)):
		if i > pos:
			ans = ans * 10 + 9
		else:
			ans = ans * 10 + s[i]
			if i == pos:
				ans -= 1
	return ans
if sum(s) >= ans:
	print(get(s, n))
else:
	print(get(s, best))


a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 18, 19, 28, 29, 38, 39, 48, 49, 58, 59, 68, 69, 78, 79, 88, 89, 98, 99, 189, 198, 199, 289, 298, 299, 389, 398, 399, 489, 498, 499, 589, 598, 599, 689, 698, 699, 789, 798, 799, 889, 898, 899, 989, 998, 999, 1899, 1989, 1998, 1999, 2899, 2989, 2998, 2999, 3899, 3989, 3998, 3999, 4899, 4989, 4998, 4999, 5899, 5989, 5998, 5999, 6899, 6989, 6998, 6999, 7899, 7989, 7998, 7999, 8899, 8989, 8998, 8999, 9899, 9989, 9998, 9999, 18999, 19899, 19989, 19998, 19999, 28999, 29899, 29989, 29998, 29999, 38999, 39899, 39989, 39998, 39999, 48999, 49899, 49989, 49998, 49999, 58999, 59899, 59989, 59998, 59999, 68999, 69899, 69989, 69998, 69999, 78999, 79899, 79989, 79998, 79999, 88999, 89899, 89989, 89998, 89999, 98999, 99899, 99989, 99998, 99999, 189999, 198999, 199899, 199989, 199998, 199999, 289999, 298999, 299899, 299989, 299998, 299999, 389999, 398999, 399899, 399989, 399998, 399999, 489999, 498999, 499899, 499989, 499998, 499999, 589999, 598999, 599899, 599989, 599998, 599999, 689999, 698999, 699899, 699989, 699998, 699999, 789999, 798999, 799899, 799989, 799998, 799999, 889999, 898999, 899899, 899989, 899998, 899999, 989999, 998999, 999899, 999989, 999998, 999999, 1899999, 1989999, 1998999, 1999899, 1999989, 1999998, 1999999, 2899999, 2989999, 2998999, 2999899, 2999989, 2999998, 2999999, 3899999, 3989999, 3998999, 3999899, 3999989, 3999998, 3999999, 4899999, 4989999, 4998999, 4999899, 4999989, 4999998, 4999999, 5899999, 5989999, 5998999, 5999899, 5999989, 5999998, 5999999, 6899999, 6989999, 6998999, 6999899, 6999989, 6999998, 6999999, 7899999, 7989999, 7998999, 7999899, 7999989, 7999998, 7999999, 8899999, 8989999, 8998999, 8999899, 8999989, 8999998, 8999999, 9899999, 9989999, 9998999, 9999899, 9999989, 9999998, 9999999, 18999999, 19899999, 19989999, 19998999, 19999899, 19999989, 19999998, 19999999, 28999999, 29899999, 29989999, 29998999, 29999899, 29999989, 29999998, 29999999, 38999999, 39899999, 39989999, 39998999, 39999899, 39999989, 39999998, 39999999, 48999999, 49899999, 49989999, 49998999, 49999899, 49999989, 49999998, 49999999, 58999999, 59899999, 59989999, 59998999, 59999899, 59999989, 59999998, 59999999, 68999999, 69899999, 69989999, 69998999, 69999899, 69999989, 69999998, 69999999, 78999999, 79899999, 79989999, 79998999, 79999899, 79999989, 79999998, 79999999, 88999999, 89899999, 89989999, 89998999, 89999899, 89999989, 89999998, 89999999, 98999999, 99899999, 99989999, 99998999, 99999899, 99999989, 99999998, 99999999, 189999999, 198999999, 199899999, 199989999, 199998999, 199999899, 199999989, 199999998, 199999999, 289999999, 298999999, 299899999, 299989999, 299998999, 299999899, 299999989, 299999998, 299999999, 389999999, 398999999, 399899999, 399989999, 399998999, 399999899, 399999989, 399999998, 399999999, 489999999, 498999999, 499899999, 499989999, 499998999, 499999899, 499999989, 499999998, 499999999, 589999999, 598999999, 599899999, 599989999, 599998999, 599999899, 599999989, 599999998, 599999999, 689999999, 698999999, 699899999, 699989999, 699998999, 699999899, 699999989, 699999998, 699999999, 789999999, 798999999, 799899999, 799989999, 799998999, 799999899, 799999989, 799999998, 799999999, 889999999, 898999999, 899899999, 899989999, 899998999, 899999899, 899999989, 899999998, 899999999, 989999999, 998999999, 999899999, 999989999, 999998999, 999999899, 999999989, 999999998, 999999999, 1899999999, 1989999999, 1998999999, 1999899999, 1999989999, 1999998999, 1999999899, 1999999989, 1999999998, 1999999999, 2899999999, 2989999999, 2998999999, 2999899999, 2999989999, 2999998999, 2999999899, 2999999989, 2999999998, 2999999999, 3899999999, 3989999999, 3998999999, 3999899999, 3999989999, 3999998999, 3999999899, 3999999989, 3999999998, 3999999999, 4899999999, 4989999999, 4998999999, 4999899999, 4999989999, 4999998999, 4999999899, 4999999989, 4999999998, 4999999999, 5899999999, 5989999999, 5998999999, 5999899999, 5999989999, 5999998999, 5999999899, 5999999989, 5999999998, 5999999999, 6899999999, 6989999999, 6998999999, 6999899999, 6999989999, 6999998999, 6999999899, 6999999989, 6999999998, 6999999999, 7899999999, 7989999999, 7998999999, 7999899999, 7999989999, 7999998999, 7999999899, 7999999989, 7999999998, 7999999999, 8899999999, 8989999999, 8998999999, 8999899999, 8999989999, 8999998999, 8999999899, 8999999989, 8999999998, 8999999999, 9899999999, 9989999999, 9998999999, 9999899999, 9999989999, 9999998999, 9999999899, 9999999989, 9999999998, 9999999999, 18999999999, 19899999999, 19989999999, 19998999999, 19999899999, 19999989999, 19999998999, 19999999899, 19999999989, 19999999998, 19999999999, 28999999999, 29899999999, 29989999999, 29998999999, 29999899999, 29999989999, 29999998999, 29999999899, 29999999989, 29999999998, 29999999999, 38999999999, 39899999999, 39989999999, 39998999999, 39999899999, 39999989999, 39999998999, 39999999899, 39999999989, 39999999998, 39999999999, 48999999999, 49899999999, 49989999999, 49998999999, 49999899999, 49999989999, 49999998999, 49999999899, 49999999989, 49999999998, 49999999999, 58999999999, 59899999999, 59989999999, 59998999999, 59999899999, 59999989999, 59999998999, 59999999899, 59999999989, 59999999998, 59999999999, 68999999999, 69899999999, 69989999999, 69998999999, 69999899999, 69999989999, 69999998999, 69999999899, 69999999989, 69999999998, 69999999999, 78999999999, 79899999999, 79989999999, 79998999999, 79999899999, 79999989999, 79999998999, 79999999899, 79999999989, 79999999998, 79999999999, 88999999999, 89899999999, 89989999999, 89998999999, 89999899999, 89999989999, 89999998999, 89999999899, 89999999989, 89999999998, 89999999999, 98999999999, 99899999999, 99989999999, 99998999999, 99999899999, 99999989999, 99999998999, 99999999899, 99999999989, 99999999998, 99999999999, 189999999999, 198999999999, 199899999999, 199989999999, 199998999999, 199999899999, 199999989999, 199999998999, 199999999899, 199999999989, 199999999998, 199999999999, 289999999999, 298999999999, 299899999999, 299989999999, 299998999999, 299999899999, 299999989999, 299999998999, 299999999899, 299999999989, 299999999998, 299999999999, 389999999999, 398999999999, 399899999999, 399989999999, 399998999999, 399999899999, 399999989999, 399999998999, 399999999899, 399999999989, 399999999998, 399999999999, 489999999999, 498999999999, 499899999999, 499989999999, 499998999999, 499999899999, 499999989999, 499999998999, 499999999899, 499999999989, 499999999998, 499999999999, 589999999999, 598999999999, 599899999999, 599989999999, 599998999999, 599999899999, 599999989999, 599999998999, 599999999899, 599999999989, 599999999998, 599999999999, 689999999999, 698999999999, 699899999999, 699989999999, 699998999999, 699999899999, 699999989999, 699999998999, 699999999899, 699999999989, 699999999998, 699999999999, 789999999999, 798999999999, 799899999999, 799989999999, 799998999999, 799999899999, 799999989999, 799999998999, 799999999899, 799999999989, 799999999998, 799999999999, 889999999999, 898999999999, 899899999999, 899989999999, 899998999999, 899999899999, 899999989999, 899999998999, 899999999899, 899999999989, 899999999998, 899999999999, 989999999999, 998999999999, 999899999999, 999989999999, 999998999999, 999999899999, 999999989999, 999999998999, 999999999899, 999999999989, 999999999998, 999999999999, 1899999999999, 1989999999999, 1998999999999, 1999899999999, 1999989999999, 1999998999999, 1999999899999, 1999999989999, 1999999998999, 1999999999899, 1999999999989, 1999999999998, 1999999999999, 2899999999999, 2989999999999, 2998999999999, 2999899999999, 2999989999999, 2999998999999, 2999999899999, 2999999989999, 2999999998999, 2999999999899, 2999999999989, 2999999999998, 2999999999999, 3899999999999, 3989999999999, 3998999999999, 3999899999999, 3999989999999, 3999998999999, 3999999899999, 3999999989999, 3999999998999, 3999999999899, 3999999999989, 3999999999998, 3999999999999, 4899999999999, 4989999999999, 4998999999999, 4999899999999, 4999989999999, 4999998999999, 4999999899999, 4999999989999, 4999999998999, 4999999999899, 4999999999989, 4999999999998, 4999999999999, 5899999999999, 5989999999999, 5998999999999, 5999899999999, 5999989999999, 5999998999999, 5999999899999, 5999999989999, 5999999998999, 5999999999899, 5999999999989, 5999999999998, 5999999999999, 6899999999999, 6989999999999, 6998999999999, 6999899999999, 6999989999999, 6999998999999, 6999999899999, 6999999989999, 6999999998999, 6999999999899, 6999999999989, 6999999999998, 6999999999999, 7899999999999, 7989999999999, 7998999999999, 7999899999999, 7999989999999, 7999998999999, 7999999899999, 7999999989999, 7999999998999, 7999999999899, 7999999999989, 7999999999998, 7999999999999, 8899999999999, 8989999999999, 8998999999999, 8999899999999, 8999989999999, 8999998999999, 8999999899999, 8999999989999, 8999999998999, 8999999999899, 8999999999989, 8999999999998, 8999999999999, 9899999999999, 9989999999999, 9998999999999, 9999899999999, 9999989999999, 9999998999999, 9999999899999, 9999999989999, 9999999998999, 9999999999899, 9999999999989, 9999999999998, 9999999999999, 18999999999999, 19899999999999, 19989999999999, 19998999999999, 19999899999999, 19999989999999, 19999998999999, 19999999899999, 19999999989999, 19999999998999, 19999999999899, 19999999999989, 19999999999998, 19999999999999, 28999999999999, 29899999999999, 29989999999999, 29998999999999, 29999899999999, 29999989999999, 29999998999999, 29999999899999, 29999999989999, 29999999998999, 29999999999899, 29999999999989, 29999999999998, 29999999999999, 38999999999999, 39899999999999, 39989999999999, 39998999999999, 39999899999999, 39999989999999, 39999998999999, 39999999899999, 39999999989999, 39999999998999, 39999999999899, 39999999999989, 39999999999998, 39999999999999, 48999999999999, 49899999999999, 49989999999999, 49998999999999, 49999899999999, 49999989999999, 49999998999999, 49999999899999, 49999999989999, 49999999998999, 49999999999899, 49999999999989, 49999999999998, 49999999999999, 58999999999999, 59899999999999, 59989999999999, 59998999999999, 59999899999999, 59999989999999, 59999998999999, 59999999899999, 59999999989999, 59999999998999, 59999999999899, 59999999999989, 59999999999998, 59999999999999, 68999999999999, 69899999999999, 69989999999999, 69998999999999, 69999899999999, 69999989999999, 69999998999999, 69999999899999, 69999999989999, 69999999998999, 69999999999899, 69999999999989, 69999999999998, 69999999999999, 78999999999999, 79899999999999, 79989999999999, 79998999999999, 79999899999999, 79999989999999, 79999998999999, 79999999899999, 79999999989999, 79999999998999, 79999999999899, 79999999999989, 79999999999998, 79999999999999, 88999999999999, 89899999999999, 89989999999999, 89998999999999, 89999899999999, 89999989999999, 89999998999999, 89999999899999, 89999999989999, 89999999998999, 89999999999899, 89999999999989, 89999999999998, 89999999999999, 98999999999999, 99899999999999, 99989999999999, 99998999999999, 99999899999999, 99999989999999, 99999998999999, 99999999899999, 99999999989999, 99999999998999, 99999999999899, 99999999999989, 99999999999998, 99999999999999, 189999999999999, 198999999999999, 199899999999999, 199989999999999, 199998999999999, 199999899999999, 199999989999999, 199999998999999, 199999999899999, 199999999989999, 199999999998999, 199999999999899, 199999999999989, 199999999999998, 199999999999999, 289999999999999, 298999999999999, 299899999999999, 299989999999999, 299998999999999, 299999899999999, 299999989999999, 299999998999999, 299999999899999, 299999999989999, 299999999998999, 299999999999899, 299999999999989, 299999999999998, 299999999999999, 389999999999999, 398999999999999, 399899999999999, 399989999999999, 399998999999999, 399999899999999, 399999989999999, 399999998999999, 399999999899999, 399999999989999, 399999999998999, 399999999999899, 399999999999989, 399999999999998, 399999999999999, 489999999999999, 498999999999999, 499899999999999, 499989999999999, 499998999999999, 499999899999999, 499999989999999, 499999998999999, 499999999899999, 499999999989999, 499999999998999, 499999999999899, 499999999999989, 499999999999998, 499999999999999, 589999999999999, 598999999999999, 599899999999999, 599989999999999, 599998999999999, 599999899999999, 599999989999999, 599999998999999, 599999999899999, 599999999989999, 599999999998999, 599999999999899, 599999999999989, 599999999999998, 599999999999999, 689999999999999, 698999999999999, 699899999999999, 699989999999999, 699998999999999, 699999899999999, 699999989999999, 699999998999999, 699999999899999, 699999999989999, 699999999998999, 699999999999899, 699999999999989, 699999999999998, 699999999999999, 789999999999999, 798999999999999, 799899999999999, 799989999999999, 799998999999999, 799999899999999, 799999989999999, 799999998999999, 799999999899999, 799999999989999, 799999999998999, 799999999999899, 799999999999989, 799999999999998, 799999999999999, 889999999999999, 898999999999999, 899899999999999, 899989999999999, 899998999999999, 899999899999999, 899999989999999, 899999998999999, 899999999899999, 899999999989999, 899999999998999, 899999999999899, 899999999999989, 899999999999998, 899999999999999, 989999999999999, 998999999999999, 999899999999999, 999989999999999, 999998999999999, 999999899999999, 999999989999999, 999999998999999, 999999999899999, 999999999989999, 999999999998999, 999999999999899, 999999999999989, 999999999999998, 999999999999999, 1899999999999999, 1989999999999999, 1998999999999999, 1999899999999999, 1999989999999999, 1999998999999999, 1999999899999999, 1999999989999999, 1999999998999999, 1999999999899999, 1999999999989999, 1999999999998999, 1999999999999899, 1999999999999989, 1999999999999998, 1999999999999999, 2899999999999999, 2989999999999999, 2998999999999999, 2999899999999999, 2999989999999999, 2999998999999999, 2999999899999999, 2999999989999999, 2999999998999999, 2999999999899999, 2999999999989999, 2999999999998999, 2999999999999899, 2999999999999989, 2999999999999998, 2999999999999999, 3899999999999999, 3989999999999999, 3998999999999999, 3999899999999999, 3999989999999999, 3999998999999999, 3999999899999999, 3999999989999999, 3999999998999999, 3999999999899999, 3999999999989999, 3999999999998999, 3999999999999899, 3999999999999989, 3999999999999998, 3999999999999999, 4899999999999999, 4989999999999999, 4998999999999999, 4999899999999999, 4999989999999999, 4999998999999999, 4999999899999999, 4999999989999999, 4999999998999999, 4999999999899999, 4999999999989999, 4999999999998999, 4999999999999899, 4999999999999989, 4999999999999998, 4999999999999999, 5899999999999999, 5989999999999999, 5998999999999999, 5999899999999999, 5999989999999999, 5999998999999999, 5999999899999999, 5999999989999999, 5999999998999999, 5999999999899999, 5999999999989999, 5999999999998999, 5999999999999899, 5999999999999989, 5999999999999998, 5999999999999999, 6899999999999999, 6989999999999999, 6998999999999999, 6999899999999999, 6999989999999999, 6999998999999999, 6999999899999999, 6999999989999999, 6999999998999999, 6999999999899999, 6999999999989999, 6999999999998999, 6999999999999899, 6999999999999989, 6999999999999998, 6999999999999999, 7899999999999999, 7989999999999999, 7998999999999999, 7999899999999999, 7999989999999999, 7999998999999999, 7999999899999999, 7999999989999999, 7999999998999999, 7999999999899999, 7999999999989999, 7999999999998999, 7999999999999899, 7999999999999989, 7999999999999998, 7999999999999999, 8899999999999999, 8989999999999999, 8998999999999999, 8999899999999999, 8999989999999999, 8999998999999999, 8999999899999999, 8999999989999999, 8999999998999999, 8999999999899999, 8999999999989999, 8999999999998999, 8999999999999899, 8999999999999989, 8999999999999998, 8999999999999999, 9899999999999999, 9989999999999999, 9998999999999999, 9999899999999999, 9999989999999999, 9999998999999999, 9999999899999999, 9999999989999999, 9999999998999999, 9999999999899999, 9999999999989999, 9999999999998999, 9999999999999899, 9999999999999989, 9999999999999998, 9999999999999999, 18999999999999999, 19899999999999999, 19989999999999999, 19998999999999999, 19999899999999999, 19999989999999999, 19999998999999999, 19999999899999999, 19999999989999999, 19999999998999999, 19999999999899999, 19999999999989999, 19999999999998999, 19999999999999899, 19999999999999989, 19999999999999998, 19999999999999999, 28999999999999999, 29899999999999999, 29989999999999999, 29998999999999999, 29999899999999999, 29999989999999999, 29999998999999999, 29999999899999999, 29999999989999999, 29999999998999999, 29999999999899999, 29999999999989999, 29999999999998999, 29999999999999899, 29999999999999989, 29999999999999998, 29999999999999999, 38999999999999999, 39899999999999999, 39989999999999999, 39998999999999999, 39999899999999999, 39999989999999999, 39999998999999999, 39999999899999999, 39999999989999999, 39999999998999999, 39999999999899999, 39999999999989999, 39999999999998999, 39999999999999899, 39999999999999989, 39999999999999998, 39999999999999999, 48999999999999999, 49899999999999999, 49989999999999999, 49998999999999999, 49999899999999999, 49999989999999999, 49999998999999999, 49999999899999999, 49999999989999999, 49999999998999999, 49999999999899999, 49999999999989999, 49999999999998999, 49999999999999899, 49999999999999989, 49999999999999998, 49999999999999999, 58999999999999999, 59899999999999999, 59989999999999999, 59998999999999999, 59999899999999999, 59999989999999999, 59999998999999999, 59999999899999999, 59999999989999999, 59999999998999999, 59999999999899999, 59999999999989999, 59999999999998999, 59999999999999899, 59999999999999989, 59999999999999998, 59999999999999999, 68999999999999999, 69899999999999999, 69989999999999999, 69998999999999999, 69999899999999999, 69999989999999999, 69999998999999999, 69999999899999999, 69999999989999999, 69999999998999999, 69999999999899999, 69999999999989999, 69999999999998999, 69999999999999899, 69999999999999989, 69999999999999998, 69999999999999999, 78999999999999999, 79899999999999999, 79989999999999999, 79998999999999999, 79999899999999999, 79999989999999999, 79999998999999999, 79999999899999999, 79999999989999999, 79999999998999999, 79999999999899999, 79999999999989999, 79999999999998999, 79999999999999899, 79999999999999989, 79999999999999998, 79999999999999999, 88999999999999999, 89899999999999999, 89989999999999999, 89998999999999999, 89999899999999999, 89999989999999999, 89999998999999999, 89999999899999999, 89999999989999999, 89999999998999999, 89999999999899999, 89999999999989999, 89999999999998999, 89999999999999899, 89999999999999989, 89999999999999998, 89999999999999999, 98999999999999999, 99899999999999999, 99989999999999999, 99998999999999999, 99999899999999999, 99999989999999999, 99999998999999999, 99999999899999999, 99999999989999999, 99999999998999999, 99999999999899999, 99999999999989999, 99999999999998999, 99999999999999899, 99999999999999989, 99999999999999998, 99999999999999999, 189999999999999999, 198999999999999999, 199899999999999999, 199989999999999999, 199998999999999999, 199999899999999999, 199999989999999999, 199999998999999999, 199999999899999999, 199999999989999999, 199999999998999999, 199999999999899999, 199999999999989999, 199999999999998999, 199999999999999899, 199999999999999989, 199999999999999998, 199999999999999999, 289999999999999999, 298999999999999999, 299899999999999999, 299989999999999999, 299998999999999999, 299999899999999999, 299999989999999999, 299999998999999999, 299999999899999999, 299999999989999999, 299999999998999999, 299999999999899999, 299999999999989999, 299999999999998999, 299999999999999899, 299999999999999989, 299999999999999998, 299999999999999999, 389999999999999999, 398999999999999999, 399899999999999999, 399989999999999999, 399998999999999999, 399999899999999999, 399999989999999999, 399999998999999999, 399999999899999999, 399999999989999999, 399999999998999999, 399999999999899999, 399999999999989999, 399999999999998999, 399999999999999899, 399999999999999989, 399999999999999998, 399999999999999999, 489999999999999999, 498999999999999999, 499899999999999999, 499989999999999999, 499998999999999999, 499999899999999999, 499999989999999999, 499999998999999999, 499999999899999999, 499999999989999999, 499999999998999999, 499999999999899999, 499999999999989999, 499999999999998999, 499999999999999899, 499999999999999989, 499999999999999998, 499999999999999999, 589999999999999999, 598999999999999999, 599899999999999999, 599989999999999999, 599998999999999999, 599999899999999999, 599999989999999999, 599999998999999999, 599999999899999999, 599999999989999999, 599999999998999999, 599999999999899999, 599999999999989999, 599999999999998999, 599999999999999899, 599999999999999989, 599999999999999998, 599999999999999999, 689999999999999999, 698999999999999999, 699899999999999999, 699989999999999999, 699998999999999999, 699999899999999999, 699999989999999999, 699999998999999999, 699999999899999999, 699999999989999999, 699999999998999999, 699999999999899999, 699999999999989999, 699999999999998999, 699999999999999899, 699999999999999989, 699999999999999998, 699999999999999999, 789999999999999999, 798999999999999999, 799899999999999999, 799989999999999999, 799998999999999999, 799999899999999999, 799999989999999999, 799999998999999999, 799999999899999999, 799999999989999999, 799999999998999999, 799999999999899999, 799999999999989999, 799999999999998999, 799999999999999899, 799999999999999989, 799999999999999998, 799999999999999999, 889999999999999999, 898999999999999999, 899899999999999999, 899989999999999999, 899998999999999999, 899999899999999999, 899999989999999999, 899999998999999999, 899999999899999999, 899999999989999999, 899999999998999999, 899999999999899999, 899999999999989999, 899999999999998999, 899999999999999899, 899999999999999989, 899999999999999998, 899999999999999999, 989999999999999999, 998999999999999999, 999899999999999999, 999989999999999999, 999998999999999999, 999999899999999999, 999999989999999999, 999999998999999999, 999999999899999999, 999999999989999999, 999999999998999999, 999999999999899999, 999999999999989999, 999999999999998999, 999999999999999899, 999999999999999989, 999999999999999998, 999999999999999999]

def maximize(n):
	result = 1
	for elem in a:
		if n >= elem:
			result = elem
		else:
			break
	return result
print(maximize(int(input())))


y = list(input())
x = [int(i) for i in y]
s0 = sum(x)
if len(x) == 1:
	print(s0)
	exit()
m = [s0, ''.join(y)]
for i in range(0, len(x) - 1):
	if sum(x[i + 1:]) + 1 < 9 * len(x[i + 1:]):
		if sum(x[:i]) + x[i] - 1 + 9 * len(x[i + 1:]) > m[0] or (sum(x[:i]) + x[i] - 1 + 9 * len(x[i + 1:]) == m[0] and int(''.join(y[:i]) + str(int(y[i]) - 1) + '9' * len(y[i + 1:])) > int(m[1])):
			m[0] = sum(x[:i]) + x[i] - 1 + 9 * len(x[i + 1:])
			m[1] = ''.join(y[:i]) + str(int(y[i]) - 1) + '9' * len(y[i + 1:])
print(int(m[1]))


def f(n):
	r = 0
	while n > 0:
		r += n % 10
		n //= 10
	return r
n = int(input())
ans = n
s = str(n)
for i in range(len(s)):
	ni = int(s[:i] + (str(chr(ord(s[i]) - 1)) if s[i] != '0' else '0') + '9' * (len(s) - i - 1))
	if ni <= n and f(ans) < f(ni):
		ans = ni
	if f(ans) == f(ni) and ni > ans:
		ans = ni
print(ans)


x = input()
y = []
y1 = []
for i in range(len(x)):
	y.append(int(x[i]))
	y1.append(int(x[i]))
a = sum(y)
i = len(x) - 2
while i >= 0:
	if y[i] != 0:
		y[i] -= 1
		for j in range(i + 1, len(x)):
			y[j] = 9
	b = sum(y)
	if b > a:
		a = b
		for j in range(len(y)):
			y1[j] = y[j]
	i -= 1
k = ''
for i in range(1, len(y1)):
	k += str(y1[i])
if y1[0] != 0:
	k = str(y1[0]) + k
print(k)


s = input()
a = list(map(int, s))
ans = a
for i in range(len(a) - 1, -1, -1):
	b = a.copy()
	if b[i] != 0:
		b[i] = int(a[i]) - 1
		b[i + 1:] = map(lambda x: 9, b[i + 1:])
	if sum(b) > sum(ans):
		ans = b
print(int(''.join(map(str, ans))))


print((lambda s: max(filter(lambda x: x <= int(s), map(int, [s, chr(ord(s[0]) - 1) + '9' * (len(s) - 1)] + [(s[0] + '9' * i + '8' + '9' * len(s))[:len(s)] for i in range(len(s) - 1)])), key=lambda x: (sum([int(i) for i in str(x)]), x)))(input()))


def Digits(x):
	ans = x
	ls = [i for i in str(x)]
	for i in range(len(ls) - 1, -1, -1):
		if ls[i] != '0':
			ls[i] = str(int(ls[i]) - 1)
			if i != len(ls) - 1:
				for i in range(i + 1, len(ls)):
					ls[i] = '9'
		temp = sum(map(int, ''.join(ls)))
		if SumOfDigits(ans) < temp:
			ans = Join(ls)
	return ans

def Join(ls):
	index = 0
	for i in range(len(ls)):
		if ls[i] == '0':
			index = i
			break
	return int(''.join(ls[index:len(ls)]))

def SumOfDigits(n):
	return n % 10 + SumOfDigits(n // 10) if n != 0 else 0
print(Digits(int(input())))


s_num = input()
num = int(s_num)
digs = [int(s_num[i]) for i in range(len(s_num))]
max_sum = sum(digs)
res = num
for i in range(len(s_num)):
	if digs[i] != 0:
		digs[i] -= 1
		n_sum = sum(digs[:i + 1]) + 9 * (len(s_num) - i - 1)
		if n_sum >= max_sum:
			n_res = int(''.join([str(digs[i]) for i in range(i + 1)]) + '9' * (len(s_num) - i - 1))
			if n_sum == max_sum:
				res = max(n_res, res)
			else:
				res = n_res
			max_sum = n_sum
		digs[i] += 1
print(res)


def e(x):
	s = 0
	while x > 0:
		s += x % 10
		x //= 10
	return s

def down(x):
	l = len(x) - 1
	return str(int(x[0]) - 1) + '9' * l
n = input()
if len(n) > 1 and n[1] == '9':
	print(n[0], end='')
	n = n[1:]
	while len(n) > 1 and n[0] == '9' and (n[1] == '9'):
		print('9', end='')
		n = n[1:]
if e(int(n)) >= e(int(down(n))):
	print(n)
else:
	print(int(down(n)))


def summaX(x):
	k = 0
	for el in x:
		k += int(el)
	return k
n = input()
N = []
Z = []
for el in n:
	N.append(el)
z = summaX(N)
Z = N.copy()
for i in range(1, len(N)):
	if int(N[i]) != 9:
		N[i - 1] = int(N[i - 1]) - 1
		for j in range(i, len(n)):
			N[j] = 9
if z >= summaX(N):
	for el in Z:
		print(el, end='')
else:
	if N[0] == 0:
		N.pop(0)
	for el in N:
		print(el, end='')


x = input()
u = len(x)

def c(x, y):
	(lx, ly) = (len(x), len(y))
	if lx > ly:
		return True
	elif lx < ly:
		return False
	else:
		ans = 0
		for i in range(lx):
			if ans == 0:
				if int(x[i]) > int(y[i]):
					ans = 1
				elif int(x[i]) < int(y[i]):
					ans = -1
		if ans >= 0:
			return True
		else:
			return False
r = str(int(x[0]) - 1) + '9' * (u - 1)
if r[0] == '0':
	r = r[1:]
i = 0
while c(x, r):
	prev = r
	r = x[0] + '9' * i + '8' + '9' * (u - i - 2)
	i += 1
if x[1:] == '9' * (u - 1):
	prev = x
print(prev)


a = input()
ans = [sum(map(int, a)), a]
for i in range(len(a) - 1, -1, -1):
	b = a[:i] + str(int(a[i]) - 1) + '9' * len(a[i + 1:])
	if a[i] != '0' and sum(map(int, b)) > ans[0]:
		ans = [sum(map(int, b)), b]
print(ans[1].strip('0'))


import sys

def getSum(n):
	sum = 0
	while n:
		sum += n % 10
		n //= 10
	return sum

def getMax(n):
	res = n
	b = 1
	while n:
		cur = (n - 1) * b + (b - 1)
		if getSum(cur) > getSum(res) or (getSum(cur) > getSum(res) and cur > res):
			res = cur
		b *= 10
		n //= 10
	return res

def main():
	n = int(sys.stdin.readline().strip())
	print(getMax(n))
main()


a = input()
last = -1
cou = 0
for j in range(len(a)):
	l = 0
	if a[j] != '0':
		l = 9 * (len(a) - j - 1)
		for t in range(j):
			l += int(a[t])
		l += int(a[j]) - 1
		if l >= cou:
			last = j
			cou = l
l = 0
for j in range(len(a)):
	l += int(a[j])
if l >= cou:
	print(a)
elif last == 0 and a[0] == '1':
	print('9' * (len(a) - 1))
else:
	print(a[:last] + str(int(a[last]) - 1) + '9' * (len(a) - last - 1))


x = input()
a = []
for i in x:
	a.append(int(i))
n = len(a)
if x.count('9', 1, n) == n - 2 and x.count('8', 1, n) == 1:
	print(x)
else:
	for i in range(1, n):
		if a[i] == 9:
			continue
		else:
			a[i - 1] -= 1
			for j in range(i, n):
				a[j] = 9
			break
	x = ''
	for i in a:
		x += str(i)
	print(x[1:n]) if x[0] == '0' else print(x)


def main():
	x = input()
	y = int(x)
	s = sum((int(d) for d in x))
	for i in range(len(x)):
		if x[i] == '0':
			continue
		z = x[:i] + str(int(x[i]) - 1) + '9' * (len(x) - i - 1)
		zi = int(z)
		t = sum((int(d) for d in z))
		if t > s or (t == s and zi > y):
			y = zi
			s = t
	print(y)
main()


from sys import exit
s = input()
i = int(s)
n = 0
k = i
while k > 0:
	n += 1
	k //= 10
if n == 1:
	print(s)
	exit()
k = 1
l = int(s[0]) * 10 ** (n - 1)
while s[k] == '9':
	k += 1
	l += 9 * 10 ** (n - k)
	if k == n:
		print(s)
		exit()
l -= 1
if '0' in s[k:] or '1' in s[k:] or '2' in s[k:] or ('3' in s[k:]) or ('4' in s[k:]) or ('5' in s[k:]) or ('6' in s[k:]) or ('7' in s[k:]):
	print(l)
elif '8' in s[1:]:
	p = s.find('8', 1)
	if '8' in s[p + 1:]:
		print(l)
	else:
		print(s)


def fun(s):
	c = 0
	for i in s:
		c += ord(i) - 48
	return c

def fun2(s):
	n = s[0]
	for i in range(1, len(s)):
		if s[i] != '9':
			i -= 1
			break
		elif i + 1 < len(s) and s[i + 1] == '9' or i + 1 == len(s):
			n += '9'
		else:
			n += '8'
			break
	n += '9' * (len(s) - i - 1)
	return n
n = input()
if len(n) > 1 and n[1] == '9':
	s = fun2(n)
else:
	s = chr(ord(n[0]) - 1) + '9' * (len(n) - 1)
s = str(int(s))
if fun(s) > fun(n):
	print(s)
else:
	print(n)


n = input()
s = str(n)
k = sum(map(int, s))
m = int(s[0]) - 1
l = m + (len(s) - 1) * 9
if k >= l:
	print(n)
elif s[1] == '9':
	x = s
	i = 0
	while s[i + 1] == '9':
		i += 1
	s = s[:i] + str(int(s[i]) - 1) + (len(s) - i - 1) * '9'
	if l <= sum(map(int, s)):
		print(int(s))
	else:
		print(x)
else:
	print(int(str(m) + '9' * (len(s) - 1)))


n = int(input())
numbers = [n]

def Summ(N):
	S = 0
	while N > 0:
		S += N % 10
		N //= 10
	return S
for i in range(0, len(str(n))):
	n -= n % 10 ** i + 1
	numbers.append(n)
Max_Summ = -1
Ans = 0
for i in numbers:
	if Summ(i) > Max_Summ:
		Max_Summ = Summ(i)
		Ans = i
print(Ans)


x = input()
l = len(x)
x = int(x)
s = '9' * l
sx = str(x)
m = int(s)
c = 0
while c != 1:
	if m > x:
		m = m - 10 ** (l - 1)
	else:
		c = 1
sm = str(m)
mm = []
for i in range(len(sm)):
	mm.append(int(sm[i]))
xx = []
for i in range(l):
	xx.append(int(sx[i]))
if m == x:
	print(m)
elif sum(xx) == sum(mm):
	print(x)
else:
	k = len(xx) - 1
	while k >= 0:
		if sum(xx) < sum(mm):
			if xx[k] == 9:
				k -= 1
			else:
				xx[k] = 9
				xx[k - 1] -= 1
				k -= 1
		else:
			if xx[0] == 0:
				xx.remove(0)
			for b in range(len(xx)):
				xx[b] = str(xx[b])
			ww = ''.join(xx)
			print(ww)
			break


def candidates(upper_bound):
	yield upper_bound
	digits = upper_bound[:-1]
	nines = []
	while digits:
		digit = digits.pop()
		nines.append(9)
		if digit != 0:
			yield (digits + [digit - 1] + nines)
upper_bound = [int(c) for c in input()]
sum_maximizer = max(candidates(upper_bound), key=sum)
if sum_maximizer[0] == 0:
	del sum_maximizer[0]
print(''.join([str(i) for i in sum_maximizer]))


a = [int(x) for x in input()]
n = len(a)
ms = 0
for i in range(n):
	if a[i] == 0:
		continue
	new_a = a[:i] + [a[i] - 1] + [9] * (n - i - 1)
	s = sum(new_a)
	if s >= ms:
		(ms, ma) = (s, new_a)
s = sum(a)
new_a = a
if s >= ms:
	(ms, ma) = (s, new_a)
print(int(''.join([str(x) for x in ma])))


def f(s):
	if len(s) == 1:
		return [int(s[0]), s]
	if s[0] == '0':
		return [f(s[1:])[0], '0' + f(s[1:])[1]]
	a = [f(s[1:])[0] + int(s[0]), s[0] + f(s[1:])[1]]
	b = [int(s[0]) + 9 * len(s) - 10, str(int(s[0]) - 1) + (len(s) - 1) * '9']
	return max(a, b)
n = input()
print(int(f(n)[1]))


def num_sum(m):
	m = list(str(m))
	l = [int(j) for j in m]
	return sum(l)
m = int(input())
l = len(str(m))
p = []
for i in range(l):
	l1 = ['9'] * l
	for j in range(i + 1):
		l1[j] = str(str(m)[j])
	ind = i
	if l1[ind] == '0':
		continue
	while int(''.join(l1)) > m and ind < len(str(int(''.join(l1)))):
		if l1[ind] == '0':
			ind += 1
		else:
			l1[ind] = str(int(l1[ind]) - 1)
	p.append(int(''.join(l1)))
(max_s, max_n) = (0, 0)
if len(p) == 1:
	print(p[0])
else:
	for i in range(len(p)):
		s = num_sum(p[i])
		if s >= max_s:
			max_s = s
			max_n = p[i]
	print(max_n)


import os
import sys
from io import BytesIO, IOBase

def main():
	b = input()
	a = list(map(int, list(b)))
	ans = int(b)
	if len(a) == 1:
		print(ans)
		return
	else:
		x = 1
		boss = ''
		while x < len(a) and a[x] == 9:
			boss += str(a[x - 1])
			x += 1
		if x == len(a):
			temp = ans
		else:
			temp = int(boss + str(a[x - 1] - 1) + '9' * (len(a) - x))
	print(ans if sum(a) >= sum(list(map(int, list(str(temp))))) else temp)
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')
main()


s = input()
for i in range(len(s) - 2, -1, -1):
	sum = 0
	for j in range(len(s) - 1, i, -1):
		sum += int(s[j])
	if sum + 1 < 9 * (len(s) - 1 - i) and s[i] != '0':
		s = s[0:i] + str(int(s[i]) - 1) + '9' * (len(s) - 1 - i)
print(int(s))


def count(x):
	cnt = 0
	for i in range(len(x)):
		cnt += int(x[i])
	return cnt
x = input()
mx = count(x)
mxs = x
for i in range(len(x) - 2, -1, -1):
	if x[i] == '0':
		continue
	temp = x[:i] + str(int(x[i]) - 1) + '9' * (len(x) - i - 1)
	if count(temp) > mx:
		mx = count(temp)
		mxs = temp
print(int(mxs))


def s(x):
	return sum((int(y) for y in str(x)))

def main():
	a = int(input())
	ss = s(a)
	aa = a
	for i in range(len(str(a)) - 1):
		x = 10 ** (i + 1)
		a //= x
		a -= 1
		a *= x
		a += x - 1
		if a > 0 and s(a) > ss:
			aa = a
			ss = s(a)
	print(aa)
main()


a = int(input())
ans = [a]
for i in range(1, len(str(a))):
	ans.append(a - a % 10 ** i - 1)
ans.sort(key=lambda z: 10000000000 - sum([int(x) for x in str(z)]))
print(ans[0])


def sum_digits(n):
	r = 0
	while n:
		(r, n) = (r + n % 10, n // 10)
	return r
number_str = input()
number = int(number_str)
max_sum = sum_digits(number)
result = number
for i in range(len(number_str) - 1, -1, -1):
	number -= int(int(number_str[i]) + 1) * pow(10, len(number_str) - (i + 1))
	number_str = str(number)
	if number < 0:
		break
	cur_sum = sum_digits(number)
	if cur_sum > max_sum:
		max_sum = cur_sum
		result = number
print(result)


def sslow(x):
	ans = (-1, -1)
	for i in range(1, x + 1):
		this = sum([int(ch) for ch in str(i)])
		ans = max(ans, (this, i))
	return ans[1]

def sfast(x):
	ans = (-1, -1)
	for i in range(x, x + 1):
		this = sum([int(ch) for ch in str(i)])
		ans = max(ans, (this, i))
	sx = str(x)
	csum = 0
	for com in range(0, len(sx) - 1):
		csum += int(sx[com])
		if sx[com] != '0':
			ch = str(int(sx[com]) - 1)
			ans = max(ans, (csum - 1 + 9 * (len(sx) - 1 - com), int(sx[:com] + ch + '9' * (len(sx) - 1 - com))))
	return ans[1]
print(sfast(int(input())))
import sys
sys.exit(0)
for x in range(1, 1000):
	if sslow(x) != sfast(x):
		print(x, sslow(x), sfast(x))
		break


integer = input()
if len(integer) > 1:
	if len(set(integer[1:])) == 1 and integer[-1] == '9':
		print(integer)
	else:
		needed_sum = sum([int(i) for i in integer])
		sum_of_two = int(integer[0]) - 1 + 9
		pairs = []
		for i in range(10):
			for j in range(10):
				if i + j == sum_of_two:
					pairs.append([str(i), str(j)])
		probable_integers = [int(''.join([str(int(integer[0]) - 1)] + ['9' for _ in range(len(integer) - 1)]))]
		for i in pairs:
			for j in range(len(integer)):
				for m in range(j + 1, len(integer)):
					result = [str(int(integer[0]) - 1)] + ['9' for _ in range(len(integer) - 1)]
					result[j] = i[0]
					result[m] = i[1]
					probable_integers.append(int(''.join(result)))
		probable_integers.append(int(integer))
		probable_integers.sort()
		a = probable_integers.index(int(integer))
		if needed_sum < sum([int(i) for i in str(probable_integers[a - 1])]):
			print(probable_integers[a - 1])
		else:
			print(integer)
else:
	print(integer)


n = int(input())
if len(str(n)) == 1:
	print(n)
else:
	cnt = 0
	while cnt + 1 < len(str(n)) and str(n)[cnt + 1] == '9':
		cnt += 1
	if cnt == 0:
		if str(n)[1] == '8' and str(n)[2:] == '9' * len(str(n)[2:]):
			print(n)
		else:
			a = str(int(str(n)[0]) - 1)
			if a == '0':
				print('9' * (len(str(n)) - 1))
			else:
				print(a + '9' * (len(str(n)) - 1))
	elif cnt == len(str(n)) - 1:
		print(n)
	else:
		ans = [str(n)]
		for i in range(1, len(str(n))):
			if str(n)[i] != '0':
				ans.append(str(n)[:i] + str(int(str(n)[i]) - 1) + '9' * (len(str(n)) - i - 1))
		anz = 0
		ans.sort(reverse=True)
		for i in range(len(ans)):
			num = ans[i]
			cnt = 0
			for j in range(len(num)):
				cnt += int(num[j])
			anz = max(anz, cnt)
			ans[i] = (num, cnt)
		for i in range(len(ans)):
			if ans[i][1] == anz:
				print(ans[i][0])
				break


x = input()

def hm(x):
	if len(x) == 1:
		return x
	elif len(x) == 2 and x[1] == '8':
		return x
	elif x[-1] == '9':
		return hm(x[:-1]) + '9'
	elif x[1:-1] == '9' * (len(x) - 2) and x[-1] == '8':
		return x
	else:
		return hm(str(int(x[:-1]) - 1)) + '9'
print(int(hm(x)))


n = input()
l = [int(i) for i in n]
ans = [sum(l), n]
for i in range(len(n) - 1):
	t0 = 0
	t1 = ''
	for j in range(len(n) - 1):
		if i == j:
			t0 += l[j] - 1
			t1 += str(l[j] - 1)
			t0 += 9 * (len(n) - j - 1)
			t1 += '9' * (len(n) - j - 1)
			break
		else:
			t0 += l[j]
			t1 += str(l[j])
	if t0 >= ans[0]:
		ans[0] = t0
		ans[1] = t1
if ans[0] == sum(l):
	ans[1] = n
print(int(ans[1]))


from random import randint

def f(s):
	a = 0
	for i in s:
		a += int(i)
	return a

def solve(n):
	n1 = list(str(n))
	ans = 0
	maxx = 0
	for i in range(len(n1)):
		n2 = n1[:i] + [str(int(n1[i]) - 1)] + ['9' for j in range(len(n1) - i - 1)]
		if f(n2) >= maxx:
			maxx = f(n2)
			ans = n2
	if f(n1) >= maxx:
		maxx = f(n1)
		ans = n1
	return [int(''.join(ans)), maxx]

def tl(n):
	ans = 0
	maxx = 0
	for i in range(1, n + 1):
		if f(list(str(i))) >= maxx:
			maxx = f(list(str(i)))
			ans = i
	return [ans, maxx]
n = int(input())
print(solve(n)[0])


x = input()
xlen = len(x) - 1
x0 = x[0]
x00 = str(int(x0) - 1)
sum = int(x00) + 9 * xlen
if x00 == '0':
	x00 = ''
ans = x00 + '9' * xlen
if int(x0 + '9' * xlen) <= int(x):
	ans = int(x0 + '9' * xlen)
	print(ans)
else:
	for i in range(xlen, 0, -1):
		a = x0 + '9' * (xlen - i) + '8' + '9' * (i - 1)
		if int(a) <= int(x):
			oldsum = sum
			sum = 0
			for i in range(len(a)):
				sum += int(a[i])
			if sum >= oldsum:
				ans = a
			else:
				sum = oldsum
	print(ans)


def rec(num):
	mod = 10
	if num < mod:
		return 0
	dom = mod
	while mod * dom < num:
		dom *= mod
	num %= dom
	if (mod * num // dom + 1) % mod:
		return num
	return rec(num)
num = int(input())
print(num - rec(num + 1))


n = int(input())
answer = n
if n >= 10:
	digits = []
	div = n
	while div != 0:
		(div, mod) = divmod(div, 10)
		digits.append(mod)
	sum1 = sum(digits)
	sum2 = digits[-1] - 1 + 9 * (len(digits) - 1)
	if sum2 > sum1:
		digits.reverse()
		buf = [9] * len(digits)
		buf[0] = digits[0]
		buf[1] = 8
		i = 1
		while buf[i] < digits[i]:
			buf[i] += 1
			buf[i + 1] -= 1
			i += 1
		buf[i] += 1
		buf[i - 1] -= 1
		answer = int(''.join(map(str, buf)))
print(answer)


def digits_sum(s):
	return sum([int(s[i]) for i in range(len(s))])

def get_max(a):
	d_s_m = 0
	r = 0
	for i in range(len(a) - 1, -1, -1):
		(x, d) = (a, int(a[i]))
		cur = d if i == len(a) - 1 else d - 1
		while cur >= 0:
			x = a[0:i] + str(cur) if i - 1 >= 0 else str(cur)
			x += '9' * (len(a) - i - 1)
			d_s = digits_sum(x)
			if d_s > d_s_m:
				d_s_m = d_s
				r = x
			cur -= 1
	while int(r[0]) == 0:
		r = r[1:]
	return r
print(get_max(input()))


x = input()
n = len(x)
if n == 1:
	print(x)
	return
ans = ''
s = 0
ps = 0
pn = ''
for i in range(n):
	ts = ps + int(x[i]) - 1 + 9 * (n - i - 1)
	if ts >= s:
		ans = pn + str(int(x[i]) - 1) + '9' * (n - i - 1)
		s = ts
	ps += int(x[i])
	pn += x[i]
if ps >= s:
	ans = pn
print(int(ans))


n = input()
l = [int(x) for x in n]
sum1 = 0
k = len(n)
ans = 0
j = 0
if k == 1:
	ans = int(n)
	sum1 = ans
elif k >= 2:
	for i in range(k - 1, 0, -1):
		ans = ans + 9 * 10 ** j
		sum1 += 9
		j += 1
	ans += (int(n[i - 1]) - 1) * 10 ** j
	sum1 += int(n[i - 1]) - 1
	k = str(ans)
	k = list(k)
	if k[0] == '9':
		k.insert(0, '1')
	else:
		k[0] = str(int(k[0]) + 1)
	while i < len(k) - 1:
		if n > ''.join([k[0]] + k[1:i] + ['8'] + k[i + 1:]):
			ans = ''.join([k[0]] + k[1:i] + ['8'] + k[i + 1:])
			i = i + 1
		else:
			break
s = sum(l)
if s >= sum1:
	print(''.join(n))
else:
	print(ans)


n = int(input())

def sumd(n):
	j = n
	sumn = 0
	while j:
		sumn += j % 10
		j //= 10
	return sumn
j = n
strn = str(n)
l = len(strn)
sumn = sumd(n)
stra = [i for i in str(n)]
i = 1
while i < l and stra[i] == '9':
	i += 1
if i != l:
	stra[i - 1] = str(int(stra[i - 1]) - 1)
	while i < l:
		stra[i] = '9'
		i += 1
ss = ''
for i in range(l):
	ss += stra[i]
if ss[0] == '0':
	ss = ss[1:]
sn = int(ss)
if sn < n and sumd(sn) <= sumn:
	ss = strn
	sn = n
print(ss)


def sum_div(n):
	summa = 0
	while n > 0:
		summa = summa + n % 10
		n = n // 10
	return summa

def run(n):
	l_n = len(n)
	left = ''
	if l_n > 2 and '9' * l_n != n and (n[1] == '9') and ('9' * (l_n - 1) != n[1:]):
		left = n[0]
		n = n[1:]
		while l_n > 1 and n[1] == '9':
			left += n[1]
			n = n[1:]
			l_n = len(n)
	l_n = len(n)
	if len(n) == 1:
		return n
	elif '9' * (l_n - 1) == n[1:]:
		return left + n
	elif n[0] != '1':
		min_number = int(str(int(n[0]) - 1) + '9' * (l_n - 1))
		if sum_div(min_number) > sum_div(int(n)):
			return left + str(min_number)
		else:
			return left + n
	else:
		min_number = int('9' * (l_n - 1)) if l_n > 1 else 0
		if sum_div(min_number) > sum_div(int(n)):
			return left + str(min_number)
		else:
			return left + n
n = input()
print(run(n))


a = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for length in range(2, 30):
	for first in range(1, 10):
		for pos in range(1, length):
			a.append(int(str(first) + '9' * (pos - 1) + '8' + '9' * (length - pos - 1)))
		a.append(int(str(first) + '9' * (length - 1)))
n = int(input())
l = 0
r = len(a)
while l < r - 1:
	middle = (l + r) // 2
	if a[middle] <= n:
		l = middle
	else:
		r = middle
print(a[l])


import sys

def calc(s):
	res = 0
	for c in s:
		res += int(c)
	return res
s = list(sys.stdin.readline().rstrip())
best = ''.join(s)
count = calc(s)
i = len(s) - 1
while i != 0:
	i -= 1
	if s[i + 1] != '9':
		s[i + 1] = '9'
		while s[i] == '0':
			s[i] = '9'
			i -= 1
		s[i] = chr(ord(s[i]) - 1)
		c = calc(s)
		if count < c:
			count = c
			best = ''.join(s)
if best[0] == '0':
	best = best[1:]
print(best)


n = int(input())
s = str(n)
k_n = 0
for x in s:
	k_n += int(x)
l0 = s
k = 0
for x in range(len(s)):
	l = s[:x] + str(max(int(s[x]) - 1, 0)) + '9' * (len(s) - x - 1)
	k_l = 0
	for y in l:
		k_l += int(y)
	if k_l >= k and int(l) <= n:
		l0 = l
		k = k_l
if k <= k_n:
	print(n)
else:
	print(int(l0))


def get(s):
	ans = 0
	for i in s:
		ans += ord(i) - ord('0')
	return ans

def solve1():
	x = input()
	n = len(x)
	best_ans = x
	best_val = get(x)
	ans = str('' if int(x[0]) - 1 == 0 else int(x[0]) - 1) + '9' * (n - 1)
	if get(ans) > best_val or (get(ans) >= best_val and int(ans) > int(best_ans)):
		best_ans = ans
		best_val = get(ans)
	for i in range(1, n):
		ans = x[:i] + str(int(x[i]) - 1) + '9' * (n - i - 1)
		if get(ans) > best_val or (get(ans) >= best_val and int(ans) > int(best_ans)):
			best_ans = ans
			best_val = get(ans)
	return best_ans
best = [0] * 10000

def solve2():
	global best
	was = 0
	for i in range(1, 10000):
		if get(str(i)) >= was:
			best[i] = i
			was = get(str(i))
		else:
			best[i] = best[i - 1]

def stress():
	solve2()
	for i in range(1, 10000):
		if int(solve1(str(i))) != best[i]:
			print(i, best[i], solve1(str(i)))
print(solve1())


s = input()
l = len(s)
pref = list(map(int, list(s)))
mx = sum(map(int, list(s)))
sm0 = mx
ans = -1
for i in range(1, l):
	pref[i] += pref[i - 1]
for i in range(l):
	if s[i] == '0':
		continue
	sm = pref[i] - 1 + 9 * (l - i - 1)
	if sm == sm0:
		continue
	if sm >= mx:
		mx = sm
		ans = i
if ans == -1:
	print(s)
else:
	print(s[:ans], end='')
	if ans == 0 and s[0] == '1':
		pass
	else:
		print(chr(ord(s[ans]) - 1), end='')
	print('9' * (l - ans - 1))


(lambda x, nx: print(int(nx) if sum(map(int, nx)) > sum(map(int, x)) else x))(*(lambda x, p: (x, x[:p] + str(int(x[p]) - 1) + (len(x) - p - 1) * '9'))(*(lambda x: (x, min([x[1:].find(str(i)) + 1 for i in range(9) if x[1:].find(str(i)) != -1] + [len(x)]) - 1))(input())))


I = lambda : int(input())
n = I()
a = list(str(n))
ans = n
total = sum(map(int, str(n)))
l = len(a)
for i in range(l - 1, -1, -1):
	if a[i] != '0':
		a[i] = str(int(a[i]) - 1)
		ctotal = sum(map(int, a))
		if total < ctotal:
			cans = int(''.join(a))
			if cans <= n:
				total = ctotal
				ans = cans
	a[i] = '9'
print(ans)


N_string = input()
N_lenght = len(N_string)
N = int(N_string)
answer = 0
answer_tmp = 0
power = 0
er = 0
for i in range(0, N_lenght - 1):
	r = N % 10
	N //= 10
	snd = N % 10
	answer_tmp += 9 * pow(10, i)
	er += 9 - r
	if r == 9:
		answer += r * pow(10, i)
		power += r
	elif r == 8 and er < 2:
		answer += r * pow(10, i)
		power += r
	else:
		answer = answer_tmp
		power += 9
		N -= 1
		er = 0
answer += N * pow(10, N_lenght - 1)
print(answer)


x = input()
variants = [x] + [str(int(x[:i]) - 1) + '9' * (len(x) - i) for i in range(1, len(x))]
print(int(max(variants, key=lambda x: (sum(map(int, x)), int(x)))))


t = input()
p = [t] + [int(t) - int(t[-k:]) - 1 for k in range(1, len(t))]
print(max(p, key=lambda q: sum(map(int, str(q)))))


x = input()
l = len(x)
dcount = 0
vcount = 0
dd = 0
for i in range(1, l):
	cur = x[i]
	if cur == '8':
		vcount += 1
	elif cur == '9':
		dcount += 1
		if dd + 1 == i:
			dd += 1
if l == 1 or ((vcount == 0 or vcount == 1) and dcount + vcount + 1 == l):
	print(x)
elif dd > 0:
	print(x[:dd] + '8' + (l - dd - 1) * '9')
else:
	t = str(int(x[0]) - 1)
	if t == '0':
		t = ''
	print(t + '9' * (l - 1))


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz/'
M = 10 ** 9 + 7
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
s = input()
n = [int(i) for i in s]
ans = (sum(n), int(s))
here = ''
c = len(n)
for i in range(len(n)):
	c -= 1
	here = s[:i] + str(n[i] - 1) + '9' * c
	su = sum(n[:i + 1]) + 9 * c - 1
	if n[i] != 0:
		ans = max(ans, (su, int(here)))
print(ans[1])


n = list(map(int, list(input())))
variants = [[9] * (len(n) - 1)]
for i in range(len(n)):
	if n[i] > 1:
		m = n[:i]
		m.append(n[i] - 1)
		for i in range(len(n) - i - 1):
			m.append(9)
		variants.append(m)
variants.append(n)
mx = []
for variant in variants:
	if sum(variant) >= sum(mx):
		mx = variant
print(''.join(map(str, mx)))


number = input()
drop = False
d8 = False
dropIndex = 0
for i in range(1, len(number)):
	if number[i] == '9' and d8 == False:
		dropIndex = i
	if number[i] >= '0' and number[i] <= '7':
		drop = True
		break
	if number[i] == '8' and d8 == True:
		drop = True
		break
	if number[i] == '8' and d8 == False:
		d8 = True
if drop:
	out = ''
	if dropIndex > 0:
		out = number
		out = out[:dropIndex] + str(int(out[dropIndex]) - 1)
	elif int(number[dropIndex]) > 1:
		out += str(int(number[dropIndex]) - 1)
	for i in range(dropIndex + 1, len(number)):
		out += '9'
	print(out)
else:
	print(number)


def digit_sum(a):
	return sum(list(map(int, list(str(a)))))

def best(x):
	poss_ans = [int(x)]
	if x[0] == '1':
		if x == '1':
			ans = '1'
		else:
			ans = '9' * (len(x) - 1)
	else:
		ans = str(int(x[0]) - 1) + '9' * (len(x) - 1)
	poss_ans.append(int(ans))
	for i in range(len(x)):
		if x[i] == '9':
			ans = x[:i] + '8' + '9' * (len(x) - i - 1)
			poss_ans.append(int(ans))
	poss_ans.sort()
	m = max(list(map(digit_sum, poss_ans)))
	for i in range(len(poss_ans)):
		if digit_sum(poss_ans[i]) == m:
			best = poss_ans[i]
	return str(best)
x = input()
print(best(x))


def sumOfDigits(a):
	return sum(map(int, str(a)))

def findMax(x):
	b = 1
	ans = x
	while x != 0:
		cur = (x - 1) * b + (b - 1)
		if sumOfDigits(cur) > sumOfDigits(ans) or (sumOfDigits(cur) == sumOfDigits(ans) and cur > ans):
			ans = cur
		x = x // 10
		b *= 10
	return ans
print(findMax(int(input())))


n = int(input())
arr = []
prefix = ''
for i in str(n):
	j = int(i)
	for num in range(j):
		arr.append(prefix + str(num) + '9' * (len(str(n)) - len(prefix) - 1))
	prefix += i
arr.append(str(n))
print(max([(sum(list(map(int, i))), int(i)) for i in arr])[1])


x = input()
sum = 0
for i in x:
	temp = int(i)
	sum += temp
xlen = len(x)
one = int(x[0])
try:
	two = int(x[1])
except:
	two = 0
if two == 9:
	count = 1
	for i in range(1, xlen):
		z = int(x[i])
		if z == 9:
			count = i
		else:
			break
	answ = x[0:count] + '8' + '9' * (xlen - count - 1)
elif one == 1:
	answ = '9' * (xlen - 1)
else:
	answ = str(one - 1) + '9' * (xlen - 1)
answ = str(answ)
sumansw = 0
for i in answ:
	temp = int(i)
	sumansw += temp
if sum >= sumansw:
	print(x)
else:
	print(answ)


def performop(arr):
	l = [arr[0]]
	used = 0
	for i in range(1, len(arr)):
		if arr[i] == 9:
			l.append(9)
		elif used == 0 and arr[i] < 8:
			l[-1] = 8
			l.append(9)
			used = 1
		elif used == 0 and arr[i] == 8:
			used = 1
			l.append(8)
		else:
			l = [arr[0]]
			for i in range(1, len(arr)):
				if arr[i] == 9:
					l.append(9)
				elif arr[i] < 9:
					l[-1] = 8
					l.append(9)
					for j in range(i + 1, len(arr)):
						l.append(9)
					break
			break
	return l

def areall9(arr):
	for i in range(1, len(arr)):
		if arr[i] != 9:
			return 0
	return 1

def restall9(arr):
	for i in range(2, len(arr)):
		if arr[i] != 9:
			return 0
	return 1

def all9last8(arr):
	for i in range(1, len(arr) - 1):
		if arr[i] != 9:
			return 0
	if arr[-1] != 8:
		return 0
	return 1

def digits(n):
	l = []
	while n > 0:
		l.append(n % 10)
		n = n // 10
	l.reverse()
	return l
n = int(input())
l = digits(n)
if len(l) == 1:
	print(n)
elif areall9(l):
	print(n)
elif l[1] == 8 and restall9(l):
	print(n)
elif all9last8(l):
	print(n)
elif l[1] == 9:
	if performop(l) != 'None':
		t = performop(l)
		for i in range(len(t)):
			print(t[i], end='')
		print()
elif l[1] == 9:
	print(l[0], end='')
	print(8, end='')
	for i in range(2, len(l)):
		print(9, end='')
	print()
else:
	if l[0] > 1:
		print(l[0] - 1, end='')
	for i in range(1, len(l)):
		print(9, end='')
	print()


def rec(num):
	mod = 10
	if num < mod:
		return 0
	pom = mod
	i = 1
	while pom < num // mod:
		i += 1
		pom *= mod
	res = num % pom
	if num != 109 and mod * num // pom % mod == 9:
		return rec(res)
	return res
num = int(input())
print(num - rec(num + 1))


def maxnum(inputdata):
	inputdata = inputdata[1:]
	(k, n, m) = (0, 0, 0)
	for i in inputdata:
		if i == '9':
			m += 1
		if i == '8':
			m += 1
	if m == len(inputdata):
		return inputdata
	if int(inputdata) < int('9' * (len(inputdata) - 1) + '8'):
		for i in inputdata:
			if i == '9':
				n += 1
			else:
				break
				n -= 1
		str2 = inputdata[:n - 1] + '8' + '9' * (len(inputdata) - n)
	else:
		str2 = inputdata
	return str2
inputdata = input()
if inputdata[0] == '0':
	h = '0'
else:
	h = inputdata[1:]
	if int(inputdata) >= 10:
		if int(h) < int('8' + '9' * (len(h) - 1)):
			h = str(int(inputdata[0]) - 1) + '9' * len(h)
		else:
			h = inputdata[0] + maxnum(inputdata)
	else:
		h = inputdata
	if h[0] == '0':
		h = h[1:]
print(h)


x = int(input())

def digit_sum(x):
	return sum([int(s) for s in str(x)])

def arr(n):
	c = []
	while n > 0:
		c.append(n % 10)
		n //= 10
	c.reverse()
	if len(c) == 0:
		c.append(0)
	return c
a1 = arr(x)
b1 = 0
for i in range(1, len(a1)):
	if a1[i] != 9:
		a1[i - 1] -= 1
		for j in range(i, len(a1)):
			a1[j] = 9
		break
a = digit_sum(x)
z = 0
c = 0
t = 1
for i in range(len(a1) - 1, -1, -1):
	c += a1[i]
	z += a1[i] * t
	t *= 10
print(x if a >= c else z)


class CodeforcesTask770BSolution:

	def __init__(self):
		self.result = ''
		self.x = 0

	def read_input(self):
		self.x = int(input())

	def process_task(self):
		ans = sum([int(c) for c in str(self.x)])
		ne = [int(x) for x in str(self.x)]
		ol = ne[:]
		for x in range(len(str(self.x))):
			if ol[-x - 1]:
				ne[-x - 1] -= 1
				for y in range(x):
					ne[-y - 1] = 9
				if sum(ne) > ans:
					ans = sum(ne)
					ol = ne[:]
		self.result = str(int(''.join([str(x) for x in ol])))

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


n = input()
num = list(map(int, list(n)))
(l, s) = (len(num), sum(num))
res = ''
sr = 0
n0 = num[0] - 1 if num[0] > 1 else 0
if s < 9 * (l - 1) + n0:
	if n0 != 0:
		res = str(n0)
		sr = n0
	res += '9' * (l - 1)
	sr += 9 * (l - 1)
else:
	print(''.join(map(str, num)))
	exit(0)
for i in reversed(range(l - 1)):
	num[i] -= 1
	num[i + 1] = 9
	s1 = sum(num)
	if s1 >= s and s1 >= sr:
		if num[0] == 0:
			num.pop(0)
		print(''.join(map(str, num)))
		exit(0)
print(res)


def my_sum(a):
	return sum([int(a) for a in a])
from collections import *
from operator import *
(x, n, flag) = (input(), deque([]), 0)
if len(x) == 1:
	exit(print(x))
for i in range(len(x)):
	if x[i] == '9':
		flag = i
	elif flag > 0:
		break
for i in range(len(x) - 1, -1, -1):
	if x[i] == '9':
		if flag == i:
			n.appendleft('8')
			flag = -1
		else:
			n.appendleft('9')
	elif i > 0:
		n.appendleft('9')
	elif flag == 0:
		n.appendleft(str(int(x[i]) - 1))
	else:
		n.appendleft(x[i])
if n[0] == '0':
	n.popleft()
(ans1, ans2) = (x, ''.join(n))
if ans2 > x:
	ans2 = '0'
ans3 = str(int(x[0]) - 1) + '9' * (len(x) - 1)
if ans3[0] == '0' and len(ans3) > 0:
	ans3 = ''.join(deque(ans3[1:]))
arr = sorted([[int(ans1), my_sum(ans1)], [int(ans2), my_sum(ans2)], [int(ans3), my_sum(ans3)]], reverse=True, key=itemgetter(1, 0))
print(arr[0][0])


def f(n, k):
	n = str(n)
	if n[k] == '0':
		return f(n, k - 1)
	a = []
	for i in n:
		a.append(int(i))
	n = a
	n[k] = int(n[k]) - 1
	n[k + 1:] = [9] * (len(n) - k - 1)
	return n
a = input()
n = len(a)
ans = [int(x) for x in a]
ms = sum(ans)
for i in range(0, n):
	ca = f(a, i)
	cs = sum(ca)
	if cs > ms:
		ans = ca
		ms = cs
	elif cs == ms:
		if int(''.join([str(_) for _ in ca])) > int(''.join([str(_) for _ in ans])):
			ans = ca
print(int(''.join([str(_) for _ in ans])))


def sum1(x):
	summa = 0
	for i in x:
		summa += int(i)
	return summa
x = input()
c = sum1(x)
result = int(x)
n = len(x) - 1
j = n
for i in range(0, n):
	if x[i] != '0':
		ni = int(x[i]) - 1
		xi = x[0:i] + str(ni) + '9' * j
		j -= 1
		ci = sum1(xi)
		if c < ci:
			c = ci
			result = int(xi)
		elif c == ci and result < int(xi):
			result = int(xi)
	else:
		j -= 1
		continue
print(result)


n = input()
k = ''
a = ''

def summa_cifr(d):
	summa = 0
	for i in str(d):
		summa += int(i)
	return summa
if n == '1':
	print(1)
elif int(n) > 17 or int(n) < 10:
	if str(int(n[0]) - 1) != '0':
		k += str(int(n[0]) - 1)
	for i in range(len(n) - 1):
		k += '9'
		a += '9'
	mass = []
	ch = 0
	vspom = str(int(n[0]))
	for i in range(len(n) - 1):
		for l in range(len(n) - 1):
			if l == ch:
				vspom += '8'
			else:
				vspom += '9'
		ch += 1
		mass.append(vspom)
		vspom = str(int(n[0]))
	mass.reverse()
	if str(int(n[0]) - 1) != '0':
		vspom = str(int(n[0]) - 1)
	else:
		vspom = ''
	mass.append(vspom + a)
	otvet = ''
	for i in mass:
		if int(n) > int(i):
			if summa_cifr(n) < summa_cifr(int(i)):
				otvet = i
				break
	if otvet:
		print(otvet)
	else:
		print(n)
else:
	print('9')


def sum_str(y):
	return sum(map(int, str(y)))
x = input()
length = len(x)
bad_answer = str(int(x[0]) - 1) + '9' * (length - 1)
total = sum_str(bad_answer)
if length == 1 or sum_str(x) >= total:
	print(x)
else:
	for i in range(length - 1, 0, -1):
		new_total = 9 * (length - i)
		new_answer = str(int(x[:i]) - 1)
		new_total += sum_str(new_answer)
		if new_total >= total:
			new_answer = new_answer if new_answer != '0' else ''
			print(new_answer + '9' * (length - i))
			break
	else:
		print(bad_answer)


n = int(input())

def f(numb):
	lst = [numb]
	cap = 10
	while numb // cap > 0:
		lst.append((numb // cap - 1) * cap + cap - 1)
		cap *= 10
	return lst

def g(numb):
	lst = []
	while numb != 0:
		lst.append(numb % 10)
		numb //= 10
	return lst
maximum = max([sum(g(i)) for i in f(n)])
maximum = [i for i in f(n) if maximum == sum(g(i))]
print(max(maximum))


n = int(input())

def get_digits_sum(n):
	s = str(n)
	t = 0
	for x in s:
		t += int(x)
	return t
s = str(n)
if len(s) == 1:
	print(n)
else:
	candidates = [n]
	for i in range(1, len(s)):
		c = s[0] + '9' * (i - 1) + '8'
		c += '9' * (len(s) - len(c))
		if int(c) <= n:
			candidates.append(int(c))
	candidates.append(int(str(int(s[0]) - 1) + '9' * (len(s) - 1)))
	answer = max(candidates, key=lambda x: (get_digits_sum(x), x))
	print(answer)


s = list(input())
s = list(map(int, s))
a = 0
q = -1
for i in range(len(s)):
	if s[i] != 0:
		t = sum(s[0:i]) + s[i] - 1 + 9 * (len(s) - i - 1)
		if t >= a:
			a = t
			q = int(''.join(map(str, s[:i])) + str(s[i] - 1) + '9' * (len(s) - i - 1))
if sum(s) >= a:
	a = sum(s)
	q = int(''.join(map(str, s)))
print(q)


def main():
	n = input()
	n1 = ''
	n1 += n[0]
	for i in range(0, len(n) - 1):
		n1 += '9'
	if int(n) == int(n1) or len(n) == 1:
		print(n)
		exit()
	count = 1
	ans = int(n1) - 1
	while ans > int(n):
		ans -= count * 9
		count *= 10
	print(ans)
main()


from math import log
x = int(input())

def digit_sum(x):
	return sum([int(s) for s in str(x)])

def brut(n):
	m = [0, 0]
	for i in range(1, n + 1):
		t = digit_sum(i)
		if m[1] <= t:
			m = (i, t)
	return m

def cnt(x):
	i = 1
	while True:
		if x // i == 0:
			break
		i *= 10
	i //= 10
	return x % i + 1

def arr(n):
	c = []
	while n > 0:
		c.append(n % 10)
		n //= 10
	c.reverse()
	if len(c) == 0:
		c.append(0)
	return c
a1 = arr(x)
b1 = 0
for i in range(1, len(a1)):
	if a1[i] != 9:
		a1[i - 1] -= 1
		for j in range(i, len(a1)):
			a1[j] = 9
		break
a = digit_sum(x)
y = x - cnt(x)
b = digit_sum(y)
z = 0
c = 0
t = 1
for i in range(len(a1) - 1, -1, -1):
	c += a1[i]
	z += a1[i] * t
	t *= 10
print(x if a >= c else z)


def f(z):
	return sum((int(i) for i in z))
x = input()
k = len(x)
m = f(x)
ans = -1
for i in range(1, k + 1):
	a = int(x[:i])
	b = x[i:]
	if not all((j == '9' for j in b)):
		a -= 1
	b = '9' * len(b)
	w = str(a) + b
	if f(w) >= m:
		m = f(w)
		ans = str(a) + b
print(int(ans))


def gh(z, i):
	k = str(z[:i]) + str(int(z[i]) - 1) + '9' * len(z[i + 1:])
	return (sum(map(int, k)), k)
a = input()
p = []
for i in range(len(a) - 1):
	if a[i] != '0':
		p.append(gh(a, i))
p.append((sum(map(int, a)), a))
print(int(sorted(p, reverse=True)[0][1]))


def sum_digits(a):
	if a < 10:
		return a
	else:
		return a % 10 + sum_digits(a // 10)

def f(a):
	a = str(a)
	return int(str(int(a[0]) - 1) + '9' * (len(a) - 1))
a = int(input())
res = f(a)
t = str(a)[0] + '9' * (len(str(a)) - 1)
res2 = 0
for i in range(1, len(t)):
	t1 = t[:i] + '8' + t[i + 1:]
	t1 = int(t1)
	if t1 <= a:
		res2 = t1
	else:
		break
ressum = sum_digits(res)
asum = sum_digits(a)
if asum > ressum:
	print(a)
else:
	print(max(res, res2))


def sum(x):
	s = 0
	for i in x:
		s += int(i)
	return s
n = input()
mmax = n
for i in range(len(n)):
	s = n[:i]
	if n[i] == '0':
		continue
	s += str(int(n[i]) - 1)
	s += '9' * (len(n) - i - 1)
	if sum(str(mmax)) < sum(s):
		mmax = int(s)
	elif sum(str(mmax)) == sum(s) and int(mmax) < int(s):
		mmax = int(s)
print(mmax)


num = list(input())
orgnum = num.copy()
if len(num) == 1:
	print(num[0])
elif num[1:] != list('9' * (len(num) - 1)):
	if num[1:] == list('8' + '9' * (len(num) - 2)):
		print(int(''.join(num)))
	elif '9' in num:
		finished = False
		did = False
		for i in range(len(num)):
			if num[i] != '9' and (not finished) and (i != 0) and (i != 1) and (orgnum[i - 1] == '9'):
				num[i - 1] = '8'
				num[i] = '9'
				finished = True
				did = True
			elif i != 0:
				num[i] = '9'
			if orgnum[i - 1] != '9' and i != 0 and (i != 1) and (not did):
				finished = True
				did = False
		for i in range(2, 13):
			if num[-i:] == ['8'] + ['9'] * (i - 1):
				num[-i:] = num[-i:][::-1]
				if int(''.join(orgnum)) < int(''.join(num)):
					num[-i:] = num[-i:][::-1]
		if not did:
			num[0] = str(int(num[0]) - 1)
		if sum([int(x) for x in num]) <= sum([int(x) for x in orgnum]):
			num = orgnum.copy()
		print(int(''.join(num)))
	else:
		print(int(str(int(num[0]) - 1) + '9' * (len(num) - 1)))
else:
	print(int(''.join(num)))


n = [int(i) for i in list(input())]
l = len(n)
s = sum(n)
ans = n.copy()
for j in range(l - 1, 0, -1):
	n[j] = 9
	if n[j - 1]:
		n[j - 1] -= 1
		x = sum(n)
		if s < x:
			s = x
			ans = n.copy()
print(int(''.join([str(i) for i in ans])))


last = ''
itog = ''
sumStart = 0
sum = 0
max = 0
k = 0
result = 0
resultS = ''
x = int(input())
s = str(x)
number = list(s)
for i in range(0, len(s)):
	sumStart = sumStart + int(s[i])
if x < 100:
	for i in range(0, x + 1):
		a = i % 10
		b = i // 10
		if a + b >= max:
			max = a + b
			result = i
			itog = str(result)
else:
	l = len(number)
	i = l - 1
	while i != 0:
		if number[i] != '9':
			m = i
			if i > 0:
				if number[i] == '8':
					k = 0
					for j in range(1, m):
						if number[j] != '9':
							k = 1
					if k == 1:
						number[i] = '9'
						number[i - 1] = str(int(number[i - 1]) - 1)
						i = i - 1
					else:
						i = i - 1
				else:
					number[i] = '9'
					number[i - 1] = str(int(number[i - 1]) - 1)
					i = i - 1
		else:
			i = i - 1
	if number[0] == '0':
		number.remove('0')
	for i in range(len(number)):
		itog = itog + number[i]
print(itog)


def summer(n):
	a = list(map(int, list(str(n))))
	return sum(a)
x = int(input())
if x // 10 == 0:
	print(x)
	exit()
else:
	max_by = summer(x)
	maximal = x
	for i in range(0, len(list(str(x))) - 1):
		a = x // 10 ** (i + 1)
		a -= 1
		a = int(str(a) + '9' * (i + 1))
		if summer(a) > max_by:
			max_by = summer(a)
			maximal = a
		elif summer(a) == max_by:
			if a > maximal:
				maximal = a
	print(maximal)


num = list(map(int, input()))
best = num[:]
for i in range(-1, -len(num) - 1, -1):
	if num[i] == 0:
		continue
	num[i] -= 1
	for j in range(i + 1, 0):
		num[j] = 9
	if sum(num) > sum(best):
		best = num[:]
s = ''.join(map(str, best)).lstrip('0')
print(s)


from sys import stdin, stdout
s = stdin.readline().strip()
value = int(s)
challengers = [str(int(str(int(s[0]) - 1) + (len(s) - 1) * '9')), s]
s = list(s[0] + (len(s) - 1) * '9')
for i in range(len(s) - 1, 0, -1):
	s[i] = '8'
	if int(''.join(s)) <= value:
		challengers.append(''.join(s))
		break
	s[i] = '9'
stdout.write(max(challengers, key=lambda x: (sum(map(int, x)), int(x))))


import math

def Summ(num):
	return sum([int(c) for c in str(num)])
numStr = input()
num = int(numStr)
maxSum = Summ(num)
maxNum = num
log = len(numStr)
for i in range(0, log - 1):
	numStr = numStr[0:log - i - 1] + str(9) + numStr[log - i:]
	curNum = int(numStr) - pow(10, i + 1)
	curSumm = Summ(curNum)
	if curSumm > maxSum:
		maxSum = curSumm
		maxNum = curNum
	elif curSumm == maxSum and curNum > maxNum:
		maxNum = curNum
print(maxNum)


from bisect import insort, bisect_right, bisect_left
from sys import stdout, stdin, setrecursionlimit
from math import sqrt, ceil, floor, factorial, gcd, log2, log10
from io import BytesIO, IOBase
from collections import *
from itertools import *
from random import *
from string import *
from queue import *
from heapq import heappush, heappop, heapify
from re import *
from os import *

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 = read(self._fd, max(fstat(self._fd).st_size, 8192))
			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 = read(self._fd, max(fstat(self._fd).st_size, 8192))
			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:
			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')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
(graph, mod, szzz) = ({}, 10 ** 9 + 7, lambda : sorted(zzz()))

def getStr():
	return input()

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

def listStr():
	return list(input())

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

def isInt(s):
	return '0' <= s[0] <= '9'

def input():
	return stdin.readline().strip()

def zzz():
	return [int(i) for i in input().split()]

def output(answer, end='\n'):
	stdout.write(str(answer) + end)

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def getPrimes(N=10 ** 5):
	SN = int(sqrt(N))
	sieve = [i for i in range(N + 1)]
	sieve[1] = 0
	for i in sieve:
		if i > SN:
			break
		if i == 0:
			continue
		for j in range(2 * i, N + 1, i):
			sieve[j] = 0
	prime = [i for i in range(N + 1) if sieve[i] != 0]
	return prime

def primeFactor(n, prime=getPrimes()):
	lst = []
	mx = int(sqrt(n)) + 1
	for i in prime:
		if i > mx:
			break
		while n % i == 0:
			lst.append(i)
			n //= i
	if n > 1:
		lst.append(n)
	return lst
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
daysInMounth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
x = getStr()
n = len(x)
if n == 1:
	exit(print(x))
ans = ''
s = 0
ps = 0
pn = ''
for i in range(n):
	ts = ps + int(x[i]) - 1 + 9 * (n - i - 1)
	if ts >= s:
		ans = pn + str(int(x[i]) - 1) + '9' * (n - i - 1)
		s = ts
	ps += int(x[i])
	pn += x[i]
if ps >= s:
	ans = pn
print(int(ans))


n = int(input())
k = [9 for i in range(len(str(n)) - 1)]
k.insert(0, int(str(n)[0]) - 1)
b = []
t = False
for l in range(len(str(n))):
	if t is True:
		b.append(9)
	elif l == 0:
		b.append(int(str(n)[0]))
	elif str(n)[l] == '9':
		b.append(9)
	else:
		b[-1] -= 1
		b.append(9)
		t = True
if sum(b) > sum(list(map(int, list(str(n))))) and sum(b) >= sum(k) and (int(''.join(list(map(str, b)))) < n):
	print(''.join(list(map(str, b))).lstrip('0'))
elif sum(list(map(int, list(str(n))))) < sum(k):
	print(''.join(list(map(str, k))).lstrip('0'))
else:
	print(n)


def cnt_sum(str_num):
	sum = 0
	for a in str_num:
		sum += ord(a) - ord('0')
	return sum
str_a = input().strip()
max_sum = cnt_sum(str_a)
ans = str_a
cnt_digit = len(str_a)
for i in range(cnt_digit - 1, -1, -1):
	if str_a[i] != '0':
		new_str = str_a[:i] + chr(ord(str_a[i]) - 1) + '9' * (cnt_digit - i - 1)
		cur_sum = cnt_sum(new_str)
		if cur_sum > max_sum:
			max_sum = cur_sum
			ans = new_str
print(int(ans))


def solve(s):
	ss = str()
	j = 0
	if s[0] == '1' and (len(s) == 1 or s[1] != '9'):
		pass
	else:
		sss = str()
		j = 1
		sss += s[0]
		while j < len(s) and s[j] == '9':
			sss += s[j]
			j += 1
		j = max(0, j - 1)
		for k in range(0, j):
			ss += sss[k]
		ss += chr(ord(s[j]) - 1)
	j += 1
	for i in range(j, len(s)):
		ss += '9'
	if sum([ord(x) - ord('0') for x in ss]) > sum([ord(x) - ord('0') for x in s]):
		return ss
	else:
		return s

def brute(n):
	maxim = 0
	ret = str()
	for i in range(1, n + 1):
		s = [ord(x) - ord('0') for x in str(i)]
		if sum(s) >= maxim:
			maxim = sum(s)
			ret = str(i)
	return ret
print(solve(input()))


a = str(input())
a_i = int(a)
l = len(a)
check = lambda x: int(''.join(map(str, x))) <= a_i
nums = [int(a[0]) - 1] + [9] * (l - 1)
m = nums[:]
for i in range(len(nums)):
	nums[i] = nums[i] + 1
	if i < l - 1:
		nums[i + 1] = nums[i + 1] - 1
	if check(nums):
		m = nums[:]
	else:
		break
print(int(''.join(map(str, m))))


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter
from itertools import combinations
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

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

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def pow(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
from functools import reduce

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

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

def prefix_sum(ar):
	return list(accumulate(ar))

def suffix_sum(ar):
	return list(accumulate(ar[::-1]))[::-1]

def N():
	return int(inp())
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]

def YES():
	print('YES')

def NO():
	print('NO')

def Yes():
	print('Yes')

def No():
	print('No')
from collections import defaultdict

def numberOfSetBits(i):
	i = i - (i >> 1 & 1431655765)
	i = (i & 858993459) + (i >> 2 & 858993459)
	return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24
tot = 200005
mod = 998244353
fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
for i in range(2, tot + 1):
	fac.append(fac[-1] * i % mod)
	inv.append(mod - inv[mod % i] * (mod // i) % mod)
	finv.append(finv[-1] * inv[-1] % mod)

def comb(n, r):
	if n < r:
		return 0
	else:
		return fac[n] * (finv[r] * finv[n - r] % mod) % mod

class MergeFind:

	def __init__(self, n):
		self.parent = list(range(n))
		self.size = [1] * n
		self.num_sets = n

	def find(self, a):
		to_update = []
		while a != self.parent[a]:
			to_update.append(a)
			a = self.parent[a]
		for b in to_update:
			self.parent[b] = a
		return self.parent[a]

	def merge(self, a, b):
		a = self.find(a)
		b = self.find(b)
		if a == b:
			return
		self.num_sets -= 1
		self.parent[a] = b
		self.size[b] += self.size[a]

	def set_size(self, a):
		return self.size[self.find(a)]

	def __len__(self):
		return self.num_sets

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

def solve():
	s = inp()
	n = len(s)

	def f(s):
		c = 0
		for i in s:
			c += int(i)
		return c
	m = f(s)
	ans = s
	for i in range(1, n):
		t = str(int(s[:i]) - 1) + '9' * (n - i)
		r = f(t)
		if r > m:
			m = r
			ans = t
		if r == m:
			ans = str(max(int(t), int(ans)))
	print(int(ans))
solve()


def digsum(a):
	sm = 0
	for i in range(len(a)):
		sm += int(a[i])
	return sm

def getv1(a):
	sec = str(int(a[0]) - 1) + '9' * (len(a) - 1)
	mx = digsum(sec)
	if digsum(a) >= mx:
		return a
	fin = ''
	for i in range(len(a)):
		if int(a[i]):
			tmp = a[:i] + str(int(a[i]) - 1) + '9' * (len(a) - i - 1)
			if digsum(tmp) >= mx:
				fin = tmp
	if not int(fin[0]):
		fin = fin[1:]
	return fin
print(getv1(input()))


x = [int(d) for d in str(int(input()))]
a = [x]
for i in range(len(x)):
	if x[i] > 0:
		t = x.copy()
		t[i] -= 1
		for j in range(i + 1, len(t)):
			t[j] = 9
		a.append(t)
a = [(sum(t), t) for t in a]
a.sort()
print(int(''.join(map(str, a[-1][1]))))


a = [int(x) for x in input()]
n = len(a)
maxm = 0
for i in range(n):
	if a[i] != 0:
		new_a = a[:i] + [a[i] - 1] + [9] * (n - i - 1)
		s = sum(new_a)
		if s >= maxm:
			(maxm, maxm_num) = (s, new_a)
s = sum(a)
if s >= maxm:
	(maxm, maxm_num) = (s, a)
print(int(''.join([str(x) for x in maxm_num])))


def cut(s):
	if str(s) == '0':
		return s
	for (i, item) in enumerate(str(s)):
		if item != '0':
			return s[i:]
	return ''

def g(sn):
	n = int(sn)
	edge = (len(sn) - 1) * 9
	res = [0] * len(sn)
	if n == 18:
		return n
	if n < 10:
		return n
	if sn[0] == '1' and sn[1] < '8':
		return '9' * (len(sn) - 1)
	if sn[1] < '8':
		return str(int(sn[0]) - 1) + '9' * (len(sn) - 1)
	is8 = -1
	for s in range(len(sn) - 1):
		if sn[s + 1] != '9':
			if is8 != -1:
				if is8 == 0:
					if sn[1] < '8':
						return '9' * (len(sn) - 1)
					else:
						k = ''
						if int(sn[0]) - 1 > 0:
							k = str(int(sn[0]) - 1)
						return k + '9' * (len(sn) - 1)
				else:
					return sn[:is8] + '8' + '9' * (len(sn) - is8 - 1)
			if sn[s + 1] == '8':
				is8 = s
				continue
			if sn[s + 1] < '8':
				return sn[:s] + '8' + '9' * (len(sn) - s - 1)
	return cut(sn)
print(g(input()))


def sum(A):
	sum = 0
	for k in A:
		sum += k
	return sum
x = input()
numbers = []
for a in x:
	numbers.append(int(a))
len = numbers.__len__() - 1
max = numbers.copy()
for i in range(len):
	numbers[len - i] = 9
	numbers[len - i - 1] -= 1
	if sum(numbers) > sum(max):
		max = numbers.copy()
answ = 0
for i in range(len + 1):
	answ += max[len - i] * 10 ** i
print(answ)


x = input()
arr = [int(i) for i in x]
if len(arr) == 1:
	print(x)
else:
	s = 0
	for i in arr[1:]:
		s += 9 - i
	if s > 1:
		ID = -1
		for i in range(1, len(arr)):
			if arr[i] != 9:
				ID = i - 1
				break
		ans = int(x[:ID] + '8' + '9' * (len(x) - ID - 1))
		if ans < int(x):
			print(ans)
		elif arr[0] > 1:
			print(str(arr[0] - 1) + '9' * (len(arr) - 1))
		else:
			print('9' * (len(arr) - 1))
	else:
		print(x)


def sumOfDigits(a):
	sm = 0
	while a != 0:
		sm = sm + a % 10
		a = a // 10
	return sm

def findMax(x):
	b = 1
	ans = x
	while x != 0:
		cur = (x - 1) * b + (b - 1)
		if sumOfDigits(cur) > sumOfDigits(ans) or (sumOfDigits(cur) == sumOfDigits(ans) and cur > ans):
			ans = cur
		x = x // 10
		b = b * 10
	return ans
n = input()
n = int(n)
print(findMax(n))


def digit_sum(n):
	res = 0
	while n > 0:
		res += n % 10
		n //= 10
	return res

def fast(n):
	if n < 10:
		return n
	s = [ord(val) - ord('0') for val in str(n)]
	for i in range(len(s) - 1):
		if s[i] >= 0 and s[i + 1] < 9:
			s[i] -= 1
			for j in range(i + 1, len(s)):
				s[j] = 9
			break
	if s[0] == 0:
		del s[0]
	s = int(''.join(map(str, s)))
	return n if digit_sum(n) >= digit_sum(s) else s
print(fast(int(input())))


x = input()
a = list(map(int, list(x)))
n = len(a)
if sum(a[1:]) == (n - 1) * 9 or sum(a[1:]) == (n - 1) * 9 - 1:
	print(x)
elif a[1] == 9:
	for i in range(1, n):
		if a[i] == 9 and a[i + 1] != 9:
			print(x[:i] + '8' + (n - 1 - i) * '9')
			break
elif a[0] == 1:
	print((n - 1) * '9')
else:
	print(str(a[0] - 1) + (n - 1) * '9')