num = gets.to_i

min = 1000000000
max = 1
diff = max - min
num.times do |i|
    data = gets.to_i
    current = data - min
    if current > diff
        diff = current
    end
    if min > data
        min = data
    end
end

puts diff