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