n = gets.chomp.to_i
input = []
n.times do
	input << gets.chomp.to_i
end
answer = nil
input.each_with_index do |subtrahend,i|
	input[i..input.size].each_with_index do |minuend,j|
		next if j == 0
		answer ||= minuend - subtrahend
		answer = minuend - subtrahend if answer < minuend - subtrahend
	end
end

puts "#{answer}"