n = int(input()) ans = n for i in range(100): ans = sum([int(s) for s in str(ans)]) print(ans)