n = gets.to_i
r = n.times.map { gets.to_i }

max_profit = r[0] - r[1]
min = r[0]
(1...r.size).each do |i|
  profit = r[i] - min
  max_profit = profit if profit > max_profit
  min = r[i] if r[i] < min
end
puts max_profit