from math import gcd from collections import Counter S=input() C=Counter(S) 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=(10*j+i)-(10*i+i) ANS=gcd(ANS,a) if C[str(j)]>=2 and C[str(i)]>0: a=(10*j+j)-(10*j+i) ANS=gcd(ANS,a) 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+k) ANS=gcd(ANS,a,b,c,d,e) if ANS==0: print(S) else: print(ANS)