n = int(input()) a = n while a >= 10: b, a = a, 0 while b != 0: a += b % 10 b //= 10 print(a)