N = gets.to_i M = gets.to_i cnt = 0 n = N while n % M != 0 && cnt < 100 n *= 10 cnt += 1 end if n % M == 0 puts (n / M).to_s.reverse.chars.find { |c| c != '0' } else puts -1 end