def c_number(N): n=0 for i in range(len(N)): n+=N[i]*(10**i) return n def gcd(a, b): while b: a, b = b, a % b return a N=list(map(int,list(input()))) if len(N) == 1: print(c_number(N)); exit() if len(N) == 2: print(gcd(c_number(N), c_number(N[::-1]))); exit() n=set(N) if len(n)==1: print(c_number(N)); exit() if len(n)==2 and 0 in n: print(c_number(sorted(N,reverse=True)));exit() s=c_number(N) if s//9 != s/9: print(1); exit() min_diff=10 for i in n: for j in n-{i}: if max(i-j,j-i)