from itertools import permutations from fractions import gcd import random g = input() digits = sorted(map(eval, str(g))) if len(set(digits)) == 1: print g elif 1 in digits or (any([x != 0 and x%2 == 0 for x in digits]) and any([x%3 == 0 for x in digits])): print 1 else: digit_len = len(str(g)) S = [] G = g sg = list(str(g)) for _ in xrange(256): random.shuffle(sg) G = gcd(int("".join(sg)), G) print G