n = STDIN.gets.to_i

n1 = STDIN.gets.to_i
n2 = STDIN.gets.to_i

max = n1
min = n1

if n1 > n2 then
  min = n2
else
  max = n2
end

diff = n2 - n1

(3..n).each { |i|
  x = STDIN.gets.to_i

  max = x if max.nil?
  min = -x if min.nil?

  if x > max then
    diff = x - min if diff.nil? or x - min > diff
    max = x
  elsif x < min then
    diff = x - max if diff.nil? or x - max > diff
    min = x
  end
}
puts diff