from functools import reduce from itertools import product from fractions import gcd N = int(input()) s = list(map(int, set(str(N)))) if len(s) == 1: print(N) else: diff = [9 * abs(x - y) for x, y in product(s, s)] print(gcd(N, reduce(gcd, diff, 0)))