n = STDIN.gets.to_i

max = -2000000000
min = STDIN.gets.to_i
diff = 0

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

  diff = if x > max - min then x else max end
  min = if x < min then x else min end
}
puts diff