def profit(array)
  profits = []
  array.each_with_index do |num1, i1|
    array.each_with_index do |num2, i2|
      if (i1 < i2) then
        profits << (num2-num1)
      end
    end
  end

  return profits.max
end

n = gets.strip.to_i
input = []
n.times do |item|
  input << gets.strip.to_i
end

p(profit(input))