n = int(input()) for i in range(99): m = 0 while(n>0): m += n%10 n //= 10 n = m print(n)