Program HOC24;
var n,i: integer;
function tcs(x: integer): integer;
var t: integer;
begin
t:=0;
while x<>0 do
begin
t:=t + (x mod 10);
x:=x div 10;
end;
tcs:=0;
end;
begin
write('N = '); readln(n);
if n>0 then
begin
for i:= n downto 1 do
if tcs(n)-tcs(i) = 1 then
begin
write('M= ',i);
break;
end;
end;
readln
end.