n = STDIN.gets.to_i
unless (2 <= n and n <= 200000)
  p ("erro: 0 <= n <= 200000")
  exit
end

xs = (0...n.to_i).map {|x| STDIN.gets.to_i }
min = 1000000001
diff_max = -1

xs.each {|x, i|
  diff = x - min
  if (diff > diff_max)
    diff_max = diff
  end
  if (x < min)
    min = x
  end
}

puts diff_max