import java.math.BigInteger;
import java.util.Scanner;
public class Main{
public static BigInteger seperate(BigInteger n){
BigInteger sum=BigInteger.ZERO;
while(!(n.divide(BigInteger.TEN).equals(BigInteger.ZERO))){
sum=sum.add(n.mod(BigInteger.TEN));
n=n.divide(BigInteger.TEN);
}
sum=sum.add(n);
//System.out.println("sum="+sum);
return sum;
import java.util.Scanner;
public class Main{
public static BigInteger seperate(BigInteger n){
BigInteger sum=BigInteger.ZERO;
while(!(n.divide(BigInteger.TEN).equals(BigInteger.ZERO))){
sum=sum.add(n.mod(BigInteger.TEN));
n=n.divide(BigInteger.TEN);
}
sum=sum.add(n);
//System.out.println("sum="+sum);
return sum;
}
public static void main(String[]args){
Scanner cin=new Scanner(System.in);
while(cin.hasNext())
{
BigInteger c=cin.nextBigInteger();
if(c.equals(BigInteger.ZERO))break;
do{c=seperate(c);}
while(!(c.divide(BigInteger.TEN).equals(BigInteger.ZERO)));
System.out.println(c);
public static void main(String[]args){
Scanner cin=new Scanner(System.in);
while(cin.hasNext())
{
BigInteger c=cin.nextBigInteger();
if(c.equals(BigInteger.ZERO))break;
do{c=seperate(c);}
while(!(c.divide(BigInteger.TEN).equals(BigInteger.ZERO)));
System.out.println(c);
}
}
}