object Main { def gcd(n: BigInt, m: BigInt): BigInt = if (n % m == 0) m else gcd(m, n % m) def solve(n: String) = n.permutations.map(d => BigInt(d)).reduce(gcd) def main(args: Array[String]) = println(solve(io.StdIn.readLine)) }