def max(a, b)
  if a.nil?
    b
  else
    (a > b) ? a : b
  end
end

def min(a, b)
  if a.nil?
    b
  else
    (a < b) ? a : b
  end
end

n = gets.to_i

data = Array.new
for i in 1..n do
  data[i-1] = gets.to_i
end

mn = data[0]
for i in 1..n-1 do
  mx = max(mx, data[i]-mn)
  mn = min(mn, data[i])
end

puts mx