import java.util.*; public class Test11 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); String[] line; line=sc.nextLine().split(" "); int n=Integer.parseInt(line[0]); for(int i=1;i<100;i++){ int tmp=n; n=0; while(tmp>0){ n+=tmp%10; tmp=tmp/10; } } String result=""+n; System.out.println(result); } }