import random import time start = time.time() S = input() def gcd(x, y): while(y): t = x x = y y = t % y return x T = 0.98 g = int(S) l = list(S) s = int("".join(sorted(l))) r = int("".join(reversed(l))) g = gcd(g, gcd(s, r)) while time.time() < start + T: random.shuffle(l) g = gcd(g, int("".join(l))) print(g)