s=gets.chomp;p s.chars.uniq.combination(2).reduce(s.to_i){|s,(x,y)|s.gcd 9*(x.to_i-y.to_i).abs}