# Here your code !
length = STDIN.gets.to_s.to_i
r = Array.new
 
for i in 0..length - 1 do
    r.push(STDIN.gets.to_s.to_i)
end
 
 
max_num = r[1]
max_point = 1
 
min_num = r[0]
min_point = 1
 
max_profit = max_num - min_num
 
k = 0
 
while k < length - 1 
    max_num = r[k+1]
    max_point = k+1
    for j in (k+1)..(length - 1) do
        if max_num <= r[j] then
            max_num = r[j]
            max_point = j
        end
    end

    for i in k..(max_point - 1) do
        if min_num > r[i]
            min_num = r[i]
            min_point = i
        end
    end

    if max_profit < max_num - min_num then
        max_profit = max_num - min_num
    end
     
    k = max_point + 1
end
 
p max_profit