
num = gets.to_i

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

puts diff