import java.util.Scanner; public class HelloWorld { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int a0 = sc.nextInt(); for (int i = 0; i < 100; i++) { a0 = nextA(a0); } System.out.println(nextA(a0)); } static int nextA(int a) { int next_a = 0; while (a > 0) { next_a += a % 10; a /= 10; } return next_a; } }