class Calc0025 def initialize(args) args = args.map { |l| l.chomp.split(/\s+/) } @n = args.shift.first.to_i @m = args.shift.first.to_i end def run n, m = @n, @m return (n / m).to_s.gsub(/0+$/, '')[-1] if n % m == 0 n, m = n / 2, m / 2 while n % 2 == 0 && m % 2 == 0 n, m = n / 5, m / 5 while n % 5 == 0 && m % 5 == 0 while m % 5 == 0 n = ((n % 10) * 10 / 5) % 10 m = m / 5 end while m % 2 == 0 n = (n % 10) % 2 == 0 ? (n % 10) / 2 : 5 m = m / 2 end m == 1 ? n : -1 end end puts Calc0025.new(STDIN.readlines).run if __FILE__ == $0