def GCD(a, b): if a < b: t = a a = b b = t if b == 0: return a r = a % b while r > 0: a = b b = r r = a % b return b N = input() Use = [False for i in range(10)] for c in N: Use[int(c)] = True if Use.count(True) == 1: print(N) else: g = 0 for i in range(9): if not Use[i]: continue for j in range(i + 1, 10): if not Use[j]: continue g = GCD(g, 9 * (j - i)) IntegerN = int(N) anser = 1 t = 1 while t * t <= g: if g % t == 0: s = g / t if IntegerN % t == 0: anser = max(anser, t) if IntegerN % s == 0: anser = max(anser, s) t += 1 print(anser)