"#{g=gets.to_i}".bytes.permutation(2){|x,y|g=g.gcd 9*y-=x};p g