n = gets.to_i
numbers = []
n.times{numbers << gets.to_i}

m = numbers.max
max_profit = m - numbers[0]
for i in (0 .. n - 2)
    profit = m - numbers[i]
    if profit == 0
        m = numbers[i + 1 .. n - 1].max
        profit = m - numbers[i]
    end
    max_profit = profit if profit > max_profit
end
puts max_profit