N = int(input()) for _ in range(100): N = sum(map(str, N)) if N < 10: break print(N)