N=input() while int(N)//10>0: ans=0 for i in N: ans+=int(i) N=str(ans) ans=N print(ans)