n = gets.to_i
ret = -1000000000
j = gets.to_i
min = j
max = j
for i in 2..n
  j = gets.to_i
  if min > j
    ret = j - min if ret < j - min
    min = j
    max = j
  end
  if max < j
    max = j
    ret = max - min if ret < max - min
  end
end
puts ret