length = gets.to_i
arr = []
length.times do
  num = gets.to_i
  arr.push num
end

def cal(length, input)
  max_prof = input[1] - input[0]
  min = input[0]
  for i in 0..(length-2) do
    diff = input[i+1] - min
    max_prof = diff if diff > max_prof

    min = input[i+1] if input[i+1] < min
  end

  p max_prof
end

cal(length, arr)



