from math import gcd from collections import Counter S=input() C=Counter(S) X=sorted(S,reverse=True) while X[-1]=="0" and len(X)>0: X.pop() X.reverse() if len(X)<1000: ANS=int("".join(X)) else: ANS=0 for i in range(10): for j in range(i+1,10): if C[str(i)]>0 and C[str(j)]>0: a=(10*j+i)-(10*i+j) ANS=gcd(ANS,a) if C[str(i)]>=2 and C[str(j)]>0: a=(100*j+10*i+i)-(100*i+10*j+i) b=(100*j+10*i+i)-(100*i+10*i+j) ANS=gcd(ANS,a,b) if C[str(j)]>=2 and C[str(i)]>0: a=(100*j+10*j+i)-(100*j+10*i+j) b=(100*j+10*j+i)-(100*i+10*j+j) ANS=gcd(ANS,a,b) for k in range(j+1,10): if C[str(i)]>0 and C[str(j)]>0 and C[str(k)]>0: a=(100*k+10*j+i)-(100*i+10*j+k) b=(100*k+10*j+i)-(100*i+10*k+j) c=(100*k+10*j+i)-(100*j+10*i+k) d=(100*k+10*j+i)-(100*j+10*k+i) e=(100*k+10*j+i)-(100*k+10*i+j) ANS=gcd(ANS,a,b,c,d,e) XS=int(S) for i in range(ANS,-1,-1): if ANS%i==0 and XS%i==0: print(i) break