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