http://acm.hdu.edu.cn/showproblem.php?pid=1013
/*
2011-9-6
author:BearFly1990
*/
package acm.hdu.tests;
import java.io.BufferedInputStream;
import java.util.Scanner;
public class HDU_1013 {
public static void main(String[] args) {
Scanner in = new Scanner(new BufferedInputStream(System.in));
while(in.hasNext()){
String inResult = in.next();
Integer result = 0;
for(int i = 0; i < inResult.length(); i++){
result = result + (inResult.charAt(i)-'0');
}
if(result == 0)break;
while(result > 9){
int temp = result;
result = 0;
while(temp > 0){
result += temp % 10;
temp /= 10;
}
}
System.out.println(result);
}
}
}