import sys import math def all_same(s): return all(c == s[0] for c in s) def main(): s = sys.stdin.readline().strip() if all_same(s): print(s) return # Compute sum of digits total = sum(int(c) for c in s) # Compute GCD of non-zero digits g = 0 for c in s: d = int(c) if d != 0: if g == 0: g = d else: g = math.gcd(g, d) # Compute P and G P = g * 9 G = math.gcd(total, P) print(G) if __name__ == "__main__": main()