n, m = $<.map(&:to_i) g = n.gcd(m) n /= g m /= g if m != 1 cnt = [0,0] while m % 2 == 0 cnt[0] += 1 m /= 2 end while m % 5 == 0 cnt[1] += 1 m /= 5 end if m != 1 p -1 exit end if cnt[0] > cnt[1] n *= 5 ** (cnt[0] - cnt[1]) else n *= 2 ** (cnt[1] - cnt[0]) end end s = n.to_s.reverse s.size.times do |i| next if s[i] == ?0 puts s[i] break end