vara,b:integer;beginreadln(a);a:=a*9;while a<>9 dobegin
b:=0; while a<>0 do begin b:=b+a mod 10; a:=a div 10; end; a:=b;end;end.
var
a,b:integer;
begin
readln(a);
a:=a*9;
while a<>9 do
begin
b:=0;
while a<>0 do
begin
b:=b+a mod 10;
a:=a div 10;
end;
a:=b;
end;
end.