import math,itertools n=list(itertools.permutations(input())) for i in range(len(n)): n[i]=int("".join(n[i])) print(math.gcd(n))