a, b = gets.chomp.split.map(&:to_i)
a_list = 1.upto(a/3).map {|e| a % e == 0 ? e : nil}.compact + [a/2, a]
b_list = 1.upto(b/3).map {|e| b % e == 0 ? e : nil}.compact + [b/2, b]
puts (a_list & b_list).max