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