def solve(): N = int(input()) while len(str(N))>1: N = sum(map(int,list(str(N)))) ans = N return ans print(solve())