import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String x = sc.nextLine();
int n = 0;
int temp = 0;
while((n = x.length())!=1){
temp = 0;
for(int i = 0; i < n; i++){
temp += Integer.valueOf(x.charAt(i)-'0');
}
x = String.valueOf(temp);
}
System.out.println(temp);
}
}
强啊,华哥