n = gets.strip.to_i
 
min = gets.strip.to_i
profit = -1000000000
 
(n-1).times do
  x = gets.strip.to_i
  pr = x - min
  if profit < pr
    profit = pr
  end
  if x < min
    min = x
  end
end
 
puts profit