#No.1168 Digit Sum Sequence N = input() while True: a = list(map(int, N)) N = sum(a) if N < 10: break else: N = str(N) print(N)