import sys input = sys.stdin.readline A=int(input()) for i in range(99): B=0 for s in str(A): B+=int(s) A=B print(A)