n = gets.to_i
nums = []
n.times do nums.push(gets.to_i) end
minvalue = nums[0]
maxprofit = -1000000000
for count in 1..(n-1) do
  maxprofit = [maxprofit, nums[count]-minvalue].max
  minvalue = [minvalue, nums[count]].min
  #puts "#{maxprofit} #{minvalue}"
end
puts maxprofit
