n = int(input()) x = n for _ in range(99): x = str(x) y = 0 for i in x: y += int(i) x = y print(x)