n = gets.chomp.to_i
rates = readlines.map(&:chomp).map(&:to_i)
maxv = (-2) * 10 ** 9
min_r = rates[0]

(1..(n - 1)).each do |i|
  maxv = maxv > rates[i] - min_r ? maxv : rates[i] - min_r
  min_r = min_r < rates[i] ? min_r : rates[i]
end

puts maxv

