n = gets.to_i
p = []
max = -1e10
c_max = -1e10
n.times do
  p.push(gets.to_i)
end

for i in 0..n-2
  if p[i] >= c_max
    c_max = p[i+1..n-1].max
  end
  max = c_max - p[i] if max < c_max - p[i]
end

puts max

