n = gets.to_i
r = []

n.times do |i|
  r[i] = gets.to_i
end

min = r[0]
max = r[1] - r[0]

1.upto(r.size-1) do |i|
  max = max < r[i] - min ? r[i] - min : max
  min = min > r[i] ? r[i] : min
end

puts max
