def f(N):
    if N==0:
        return 0
    else:
        return f(N//10)+N%10

N=int(input())
for i in range(100):
    N=f(N)
print(N)