import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from functools import reduce from math import gcd Nstr = [int(x) - ord('0') for x in read().rstrip()] nums = sorted(set(Nstr)) if len(nums) == 1: print(''.join(map(str,Nstr))) exit() diff = [y - x for x,y in zip(nums,nums[1:])] d = reduce(gcd,diff) d *= 9 N = int(''.join(map(str,Nstr))) answer = gcd(N,d) print(answer)