from itertools import chain from fractions import gcd from itertools import permutations st=raw_input() lst=[] for l in list(permutations(st,len(st))): lst.append( ''.join(list(chain.from_iterable(l))).lstrip("0")) print reduce(gcd, map(long,lst))