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

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