#include <iostream>
using namespace std;
int TheNumberOfDigits(int n)//Количество цифр в числе
{
int i=1;
while ((n/=10)>0)
{
i++;
}
return i;
}
int sc(int a) //Сумма цифр числа
{
int sum = 0;
while (a/1>0)
{
sum+=a%10;
a/=10;
}
return sum;
}
int main()
{
int n, v, t, x, a;
cin>>n;
a=10;
unsigned int b=100;
t=TheNumberOfDigits(n);
x=n;
for (int i=1;i<t;i++)
{
v=(n/b)*b+(n%b/a-1)*a+a-1;
if (sc(v)>sc(x))
x=v;
a*=10;
b*=100;
}
cout<<x<<endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IFRoZU51bWJlck9mRGlnaXRzKGludCBuKS8v0JrQvtC70LjRh9C10YHRgtCy0L4g0YbQuNGE0YAg0LIg0YfQuNGB0LvQtQp7CglpbnQgaT0xOwogICAgd2hpbGUgKChuLz0xMCk+MCkKICAgIHsKICAgIAlpKys7CiAgICB9CiAgICByZXR1cm4gaTsKfQoKaW50IHNjKGludCBhKSAvL9Ch0YPQvNC80LAg0YbQuNGE0YAg0YfQuNGB0LvQsAp7CglpbnQgc3VtID0gMDsKCXdoaWxlIChhLzE+MCkKCXsKCQlzdW0rPWElMTA7CgkJYS89MTA7Cgl9CQoJcmV0dXJuIHN1bTsKfQoKaW50IG1haW4oKQp7CglpbnQgbiwgdiwgdCwgeCwgYTsKCWNpbj4+bjsKCWE9MTA7Cgl1bnNpZ25lZCBpbnQgYj0xMDA7Cgl0PVRoZU51bWJlck9mRGlnaXRzKG4pOwoJeD1uOwoJZm9yIChpbnQgaT0xO2k8dDtpKyspCgl7CgkJdj0obi9iKSpiKyhuJWIvYS0xKSphK2EtMTsKCQlpZiAoc2Modik+c2MoeCkpCgkJCXg9djsKCQlhKj0xMDsKCQliKj0xMDA7Cgl9Cgljb3V0PDx4PDxlbmRsOwoJcmV0dXJuIDA7Cn0=