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