n = gets.to_i
numbers = []
n.times{numbers << gets.to_i}

max_profit = numbers[1] - numbers[0]
for i in (0 .. n-2)
    for j in (i+1 .. n-1)
        max_profit = numbers[j] - numbers[i] if numbers[j] - numbers[i] > max_profit    
    end
end
puts max_profit