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