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

(1..n).each { |i|
  x = STDIN.gets.to_i
  if x > max then
    diff = max - min
    max = x
    min = x
  elsif x < min then
    min = x
    diff = max - min if max - min > diff
  end
}
puts diff