def gcd(x,y): return x if y == 0 else gcd(y,x%y) N = input() n = int(N) s = set(map(int,list(N))) if len(s) == 1: print(N) else: G = n for i in s: for j in s: if i < j: if G == 0: G = 9 * (j - i) else: G = gcd(G,9 * (j - i)) print(G)