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