n = int(input()) x = n for i in range(1, 100): x = sum(list(map(int, list(str(x))))) print(x)