Var
a, b: integer;
begin
readln(a);
while (inttostr(a).Length > 1) do
begin
b := 0;
foreach c: char in inttostr(a) do
b += strtoint(c);
a := b;
end;
writeln(b);
end.
=======================
var
a, b, e: integer;
d: string;
begin
readln(a);
d := inttostr(a);
while (length(d) > 1) do
begin
d := inttostr(a);
b := 0;
for e := 1 to length(d) do
b += strtoint(d[e]);
a := b;
end;
writeln(b);
end.