n = gets.to_i
monster = gets.split(" ").map(&:to_i)

max_hp = monster.max

min_hp = 100000000000000

monster.each do |hp|
  a = max_hp % hp 
  tmp_min = hp if a == 0
  tmp_min = hp - a if a != 0

  min_hp = tmp_min if min_hp > tmp_min
end
p min_hp
