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