import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); sc.close(); for (int i = 1; i < 100; i++) { int x = 0; while (n > 0) { x += n % 10; n /= 10; } n = x; } System.out.println(n); } }