import math def compute_gcd(n_str): # Check if all characters are the same if all(c == n_str[0] for c in n_str): return n_str # Compute sum of digits s = sum(int(c) for c in n_str) # Compute minimal element m digits = sorted(n_str) # Find the first non-zero digit first_non_zero = next(i for i, d in enumerate(digits) if d != '0') # Form the minimal element minimal_digits = [digits[first_non_zero]] + digits[:first_non_zero] + digits[first_non_zero+1:] m_str = ''.join(minimal_digits) # Compute m mod s mod = 0 for c in m_str: mod = (mod * 10 + int(c)) % s # GCD of s and mod g = math.gcd(s, mod) return str(g) n = input().strip() print(compute_gcd(n))