n=input() while len(n)!=1: n=str(sum([int(i)for i in n])) print(n)