n = gets.chomp.to_i

rates = []
n.times do
  rates << gets.chomp.to_i
end

minv = rates[0]
maxv = -20000000000
for num in 1..(n - 1) do
  maxv = [maxv, rates[num]-minv].max
  minv = [minv, rates[num]].min
end

puts maxv
