t = gets.to_i
arr=Array.new()
t.times do
  arr.push gets.to_i
end

maxv=arr[1]-arr[0]
minv=arr[0]
(1..t-1).each do |j|
  maxv= maxv>(arr[j]-minv) ? maxv : (arr[j]-minv)
  minv= minv<arr[j] ? minv : arr[j]
end
puts maxv