n = gets.to_i
min = last = gets.to_i
max = 0
profits = []
(n-1).times{
  current = gets.to_i
  catch(:next) do
    if (current <= min)
      profits<<(current-last) if (profits.bsearch{|i| i >= 0} == nil)
      min = current
      throw :next
    end
    max = current if (current > last)
    profits<<(max-min)
  end
  last = current
}
puts profits.max