data = STDIN.read.lines[1..-1].map(&:to_i)
min_elem = data[0]
max_diff = data[1] - data[0]
data[1..-1].each { |n|
  d = n - min_elem
  max_diff = d if (d > max_diff)
  min_elem = n if (n < min_elem)
}
puts max_diff