class AOJ
  def initialize
    n = gets.chomp.to_i
    answer = -10e10
    min_value = 10e10

    n.times do |i|
      r = gets.chomp.to_i

      profit = r - min_value

      min_value = [min_value, r].min

      if i.nonzero?
        answer = [answer, profit].max
      end
    end

    puts answer
  end
end

AOJ.new