n = gets.to_i
j = gets.to_i
min = j
max = j
ret = -1000000000

for i in 2..n
    j = gets.to_i
    if j <= min then
        ret = j - min if ret < j - min
        min = j
        max = j
    end
    if j > max then
         max = j
         ret = max - min if ret < max - min
    end

end

puts ret
