N = int(input()) def calc(x): s = 0 while x: s += x % 10 x = x // 10 return s for _ in range(99): N = calc(N) print(N)