import math s = input() st = set() for i in s: st.add(int(i)) ans = int(s) if len(st) == 1: print(ans) else: for i in st: for j in st: if j > i: ans = math.gcd(ans, 9*(j - i)) print(ans)