n = gets.chomp.to_i
max_profit = (10 ** 9) * -1
min_val = gets.chomp.to_i

(n-1).times do
  r = gets.chomp.to_i
  max_profit = max_profit > (r - min_val) ? max_profit : (r - min_val)
  min_val = min_val < r ? min_val : r
end

puts max_profit