import math n=int(input()) t=set() [t.add(int(c))for c in str(n)] for a in t: for b in t: n=math.gcd(n,9*(a-b)) print(n)