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