n = gets.chomp.to_i
r = []

for i in (0..n-1) do 
    r[i] = gets.chomp.to_i
end

min = r[0]
max = r[1]
profit = max - min
for i in (1..n-1) do 
    if r[i] < min then
        min = r[i]
        max = r[i]
        next
    end
    max = r[i] if r[i] > max
    profit = max - min if profit < (max - min)
end

puts profit



