n = gets.chomp.to_i
data = Array.new
max = -1000000000
min = 1000000000

n.times { |i|
	data[i] = gets.chomp.to_i
	
	if i!=0
		diff = data[i] - min
		if max<diff
			max=diff
		end
	end
	
	if min>data[i]
		min=data[i]
	end
}

puts max