#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_D

n = gets.to_i
arr = []
n.times do
    arr.push gets.to_i
end

maxv=arr[1]-arr[0]
minv = arr[0]
(1..n-1).each do |j|
    maxv = arr[j]-minv if maxv < arr[j]-minv
    minv = arr[j] if minv > arr[j]
end

puts maxv