N = int(input()) print(9 if N % 9 == 0 else N % 9)