def wa(n): res=0 while n: res+=n%10 n//=10 return res N=int(input()) vec=[0]*101 vec[0] = N for i in range(1,101): vec[i] = wa(vec[i - 1]) print(vec[99])