import sys input=sys.stdin.readline def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def main(): mod=10**9+7 N=I() def calc(X): temp=0 while X!=0: temp+=X%10 X=X//10 return temp ans=N for i in range(99): ans=calc(ans) print(ans) main()