num = gets.to_i

min = gets.to_i
diff = 1 - 1000000000
(num-1).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