n = gets.to_i
rs = []
n.times do
  rs << gets.to_i
end

max = -10 ** 9
max_i = 0
min = rs[0]
rs.length.times do |i|
  break if i == rs.length - 1
  next if rs[i] > min
  min = rs[i]
  if i < max_i
    max = rs[max_i] - rs[i]
  else
    (i+1..rs.length-1).each do |j|
      if rs[j] - rs[i] > max
        max = rs[j] - rs[i]
        max_i = j
      end
    end
  end
end

puts max