n = int(input()) if n % 9 == 0: print(9) else: print(n % 9)