s = gets.chomp
ans = s.to_i
a = s.split('')
100.times{|i|
    a.shuffle!
    ans = ans.gcd(a.join.to_i)
    }
p ans