from itertools import product from math import gcd sg = input() g = int(sg) digits = sorted(map(eval, str(g))) 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)