n = int(input()) a = n for i in range(99): tmp = str(a) t = 0 for j in tmp: t += int(j) a = t print(a)