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