n = gets.to_i
prices = []
n.times { prices << gets.to_i }

memo = -1_000_000_001
tmp_max = 0

prices.reverse.each_cons(2) do |n, m|
  tmp_max = n if [tmp_max, n].max > tmp_max
  memo = tmp_max - m if tmp_max - m > memo
end

puts memo