def sum(n): for i in range(100): temp=0 for j in range(len(str(n))): temp+=int(str(n)[j]) n=temp return n N = int(input()) print(sum(N))