package com.peter;
import java.util.Scanner;
public class HD1013 {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
String str = cin.next();
while((str != null)&&(!str.equals("0"))){
System.out.println(num(str));
str = cin.next();
}
}
public static int num(String str){
int root=0;
for(int i=0;i<str.length();i++){
root += Integer.parseInt(str.charAt(i)+"");
}
if(root>9){
return num(String.valueOf(root));
}else{
return root;
}
}
}
/* public static int num(int n){
int root=0;
while(n !=0){
root += n%10;
n = (int)(n/10);
}
if((int)(root/10) != 0){
return num(root);
}else return root;
}*/