n = int(input()) def f(a): s = str(a) ret = 0 for i in s: ret += int(i) return ret for _ in range(100): n = f(n) print(n)