n = int(input()) a = [0]*100 a[0] = n for i in range(99): b = 0 s = str(a[i]) for x in s: b += int(x) a[i+1] = b print(a[-1])