(d="#{g=gets.to_i}".bytes|[]).map{|x|d.map{|y|g=g.gcd 9*y-=x}};p g