=begin
1
3
4
3
10
=end
n = gets.to_i

a = []
n.times do |i|
    a.push(gets.to_i)
end

m = a[1] - a[0]
b = a[0]

(1...a.size).each do |i|
    if a[i] - b > m then
        m = a[i] - b
    end

    if a[i] < b then
        b = a[i]
    end
end

print m, "\n"

