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

max_monster = monster.max

min_hp1 = 100000000000000

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

  min_hp1 = tmp_min if min_hp1 > tmp_min
end

min_monster = monster.min

min_hp2 = 100000000000000

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

  min_hp2 = tmp_min if min_hp2 > tmp_min
end

if min_hp1 > min_hp2
  puts min_hp2
else
  puts min_hp1
end
