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