from math import gcd N = input() S = set() for c in N: S.add(int(c)) if len(S) == 1: print(N) else: G = 0 for y in S: for x in S: if y > x: G = gcd(G, 9*(y-x)) ans = gcd(int(N), G) print(ans)