def f(n): sum = 0 for i in str(n): sum += int(i) if 0 < n < 10: return n return f(sum) n = int(input()) print(f(n))