n = gets.to_i
min_price = gets.to_i
max_profit = nil
(n - 1).times{
    price = gets.to_i
    max_profit = price - min_price if max_profit.nil? || max_profit < price - min_price
    min_price = price if min_price > price
}
puts max_profit
#??\???????§£??¬???????????????????§£???
#http://judge.u-aizu.ac.jp/onlinejudge/commentary.jsp?id=ALDS1_1_D