n=int(input()) for _ in range(99): m=0 for i in str(n): m+=ord(i)-ord('0') n=m print(n)