n = gets.to_i
l = Array.new
n.times do
  l << gets.to_i
end

max = -1000000000
min = l[0]
(1..n-1).each do |i|
  if max < l[i] - min then
    max = l[i] - min
  end
  if min > l[i] then
    min = l[i]
  end
end

puts max

