N = int(input()) x = [N] for i in range(99): x.append(sum(map(int, str(x[-1])))) print(x[-1])