import sys ini = lambda: int(sys.stdin.readline()) def dsum(x): s = 0 while x: s += x % 10 x //= 10 return s def solve(): n = ini() a = n for i in range(2, 101): a = dsum(a) return a print(solve())