n = gets.to_i m = gets.to_i a = Array.new(2, 0) g = n.gcd(m) n /= g m /= g tm = m while tm % 2 == 0 || tm % 5 == 0 do if tm % 2 == 0 tm /= 2 a[0] += 1 end if tm % 5 == 0 tm /= 5 a[1] += 1 end end if tm != 1 puts -1 exit end b = (a[0] > a[1]) ? a[0] : a[1]; r = (10 ** b) / m s = (r * n).to_s (s.length - 1).downto(0) do |i| if s[i].to_i != 0 puts s[i] break end end