require 'prime'

def gcd(l, r)
  return r if l%r==0
  gcd(r, l%r)
end

n, m = gets.strip.split.map(&:to_i)

result = 1
current = m/n

(m/n).times do |num|
  if current.prime?
    current -= 1
    next
  end

  tmp_result = gcd(current + m%current, current)
  result = tmp_result if tmp_result > result
  current -= 1
end

p result

