def geta(n=0)
  return $stdin.gets.to_i if n==0
  ar = []
  n.times do 
    ar << $stdin.gets.chomp.split
  end
  return ar.flatten(1) if n<=1
  return ar
end

def jadge(n)
  sqrt = Math.sqrt(n).ceil
  2.step(sqrt) do |i|
    return 0 if n%i == 0
  end
  return 1
end

n = geta(0)
ar = geta(n)

result = []
buyv,celv = 0,0
ar.flatten.map(&:to_i).each_with_index do |n,i|
  if i==0
    buyv = n
    next
  end
  result << n - buyv
  buyv = n if n < buyv
end
p result.max
