n = gets.to_i
r = Array.new

n.times do
    r.push(gets.to_i)
end

# initialize max
max_r = r[1] - r[0]
min_v = r[0] < r[1] ? r[0] : r[1]
# calc
for i in 2..n-1 do
    current = r[i] - min_v
    max_r = current if current > max_r
    min_v = r[i] if r[i] < min_v
end

puts max_r