import random import fractions s = input() n = int(s) a = [0]*10 for i in s: a[int(i)]+=1 ans = n for i in range(10): for j in range(i): if a[i] and a[j]: if ans < 0: ans = 9*(i-j) else: ans = fractions.gcd(ans, 9*(i-j)) print(ans)