import math g=int(input()) d=list({int(i)for i in str(g)}) d=[[i,j] for i in d for j in d] for x,y in d:g=math.gcd(g,9*(x-y)) print(g)