def f(x): res = 0 s = str(x) for ss in s: res += int(ss) return res n = int(input()) a = [0]*100 a[0] = n for i in range(1, 100): a[i] = f(a[i-1]) print(a[99])