require 'prime'

N, M = gets.split.map(&:to_i)

class Integer
  def divisor_list
    return [] if self <= 0
    return [1] if self == 1

    prime_division.map{|e| [*(0..e.last)].map{|v| e.first ** v }}.inject{|res, e| res.map{|t| e.map{|v| t * v}}.flatten}.sort
  end
end


cand = M.divisor_list

ans = 0

cand.each do |i|
  remain = M - i * N
  next if remain < 0

  if remain % i == 0
    ans = i
  end
end

puts ans
