import java.util.*; import java.io.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); PrintWriter ou = new PrintWriter(System.out); int n = Integer.parseInt(sc.next()); for(int i = 0 ; i < 100 ; i++){ int s = 0 , cl = n; while(cl != 0){ s += cl % 10; cl /= 10; } n = s; } ou.println(n); ou.flush(); sc.close(); } }