from fractions import gcd from itertools import permutations st=raw_input() lst=[] for l in list(permutations(st,len(st))): lst.append(reduce(lambda x,y: x+y,l).lstrip("0")) print reduce(gcd, map(int,lst))