N = int(input()) A = [N] while len(str(A[-1])) != 1: A.append(sum(list(map(int, list(str(A[-1])))))) print(A[-1])