n = STDIN.gets.to_i
max = 0
min = 0
diff = nil

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

  min = x if min == 0

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