n = gets.to_i
arr = []
n.times { |i| arr << gets.chomp.to_i }

min = arr[0]
max_diff = arr[1] - min
(1...n).each_with_index do |i|
  diff = arr[i] - min
  min = arr[i] if arr[i] < min
  max_diff = diff > max_diff ? diff : max_diff
end

puts max_diff

