from math import gcd def solve(N): Nt = tuple(int(x) for x in N) st = set(Nt) if len(st) == 1: return N sr = sorted(st) diff = 9 for i in range(1, len(sr)): diff = min(diff, sr[i] - sr[i - 1]) S = sum(Nt) return gcd(S, diff * 9) print(solve(input()))