require 'prime'

n, m = gets.split.map(&:to_i)
divisions = m.prime_division
opts = []
divisions.each do |d, count|
  count.times { opts << d }
end
divisor = m
(2 ** opts.size).times do |i|
  product = 1
  opts.size.times do |bit|
    product *= opts[bit] if i[bit] == 1
  end
  divisor = product if divisor > product && n <= product
end
puts m / divisor
