arr = []
n = gets.to_i
n.times do
  input = gets.to_i
  arr << input
end
max = -2000000000000000
(arr.length-1).times do |i|
  result = arr[(i+1)..-1].max - arr[i]
  max = result if(result > max)
end
p max
