n = gets.to_i

pre_minnumber = gets.to_i
ans_max = -Float::INFINITY

(n-1).times do
    y = gets.to_i
    if ans_max < (y-pre_minnumber)
        ans_max = y - pre_minnumber
    end
    if pre_minnumber > y
        pre_minnumber = y
    end
end

puts ans_max
