MODE = "stdiro"
#require 'matrix'
#include Math
line = Array.new

if(defined? MODE)
  line = STDIN.read.split("\n")
else
  tmp = '3
  4
  3
  2'.split("\n")
  tmp.each{|s|
    line << s.strip
  }
end


n = line[0].to_i

arr=[]
(1..n).each do |num|
  arr << line[num].to_i
end


minv = arr[0]
maxv = -10**9
(1..n-1).each do |j|
  maxv = [maxv, arr[j]-minv].max
  minv = [minv, arr[j]].min
end

puts maxv