# import pypyjit # pypyjit.set_param('max_unroll_recursion=-1') from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline N = int(input()) def f(x): X = list(str(x)) X = [int(i) for i in X] return sum(X) tN = N for i in range(99): tN = f(tN) print(tN)