class String
  def to_ia
    self.split(/\s+/).map {|s| s.to_i}
  end
end
 
def maximun_profit(numbers)
  min = numbers[0]
  max = nil
  numbers[1..-1].each do |n|
    val = n - min
    max = max ? [max, val].max : val
    min = [min, n].min
  end
  max
end
 
lines = STDIN.read.split(/\n/)
numbers = lines[1..-1].map {|l| l.to_i}
puts maximun_profit(numbers)