import random import fractions n = input() nn = len(n) a = [] for i in n: a.append(i) a.sort() b = 0 for i in a: b *= 10 b += int(i) # print(b) a.sort(reverse=True) c = 0 for i in a: c *= 10 c += int(i) # print(c) def gcd(a, b): if a == 0: return b if b == 0: return a return gcd(b, a%b) ans = fractions.gcd(b, c) for i in range(100): for j in range(200): aa = random.randint(0, nn-1) bb = random.randint(0, nn-1) a[aa], a[bb] = a[bb], a[aa] d = 0 for i in a: d *= 10 d += int(i) ans = fractions.gcd(ans, d) print(ans)