min_  = 1000000000
difmax=-1000000000
cnt=0
n = STDIN.gets.split[0].to_i
0.upto(n-1) {|i| 
  n = STDIN.gets.split[0].to_i
 
  dif = n - min_
  if n < min_
    min_ = n
  end
  
 
  difmax = dif if dif > difmax
}
puts difmax