n = input().strip() # Check if all digits are the same all_same = True first = n[0] for c in n: if c != first: all_same = False break if all_same: print(n) else: s = sum(int(c) for c in n) if s % 9 == 0: print(s) else: import math g = math.gcd(s, 9) print(g)