from itertools import product from math import gcd S=input();g=int(S) d=[i for i in range(10) if S.find(str(i)) != -1] if len(d) == 1:print(g) else: G=g for x in product(d, repeat=2): G=abs(gcd(G,9*(x[0]-x[1]))) print(G)