n = gets.to_i
r = []
profit = 0-1000000000
n.times {
	num = gets.to_i
	( r.length-1 ).downto( 0 ) { |j|
		diff = num - r[j]
		if profit < diff
			profit = diff
		end
	}	
	r.push( num )
}
puts( profit )