import random import fractions s = input() g = int(s) l = list(s) for i in range(500): random.shuffle(l) g = fractions.gcd(g,int(''.join(l))) print(g)