min = 10 ** 9 + 1
max = 0
benefit = 0
prev = 10 ** 9 + 1
lost = - 10 ** 9
gets.to_i.times do
  r = gets.to_i
  if r < min
    min = r
    max = 0
  elsif r >= max
    max = r
    if max - min > benefit
      benefit = max - min
    end
  end
  if lost < r - prev
    lost = r - prev
  end
  prev = r
end
if lost > 0
  puts benefit
else
  puts lost
end