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