arr = []
results = []
n = gets.to_i
n.times do
  input = gets.to_i
  arr.push(input)
end
arr.each_with_index do |num, index|
  break if(num == arr[-1]) 
  result = arr[(index+1)..-1].max - num
  results.push(result)
end
p results.max
