def profit(array)
  max = nil
  for i1 in 0...array.size do
    for i2 in i1+1...array.size do
      diff = array[i2] - array[i1]
      if (max == nil || max < diff) then
        max = diff
      end
    end
  end

  return max
end

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

p(profit(input))