def profit(array)
  return array[0] if array.size() == 1
  min = (array[0] > array[1]) ? array[1] : array[0]
  max_profit = array[1] - array[0]

  array.each_with_index do |num, i|
    next if (i < 2)
    if (num < min) then
      min = num
    else
      diff = num - min
      max_profit = diff if (diff > max_profit)
    end
  end

  return max_profit
end

n = gets.strip.to_i
input = []
n.times do |item|
  input << gets.strip.to_i
end

p(profit(input))