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

maxv, minv = -(10**10), 10**10

while rs.size > 0
  now = rs.shift
  maxv = maxv < (now-minv) ? (now-minv) : maxv
  minv = now < minv ? now : minv
end
puts maxv
