N = int(input()) res = N for i in range(100): res = sum(map(int, str(res))) print(res)