n = int(input()) ans = n for i in range(99): temp = 0 while n != 0: temp += n % 10 n //= 10 ans = temp n = temp print(ans)