import sys

n = int(input())
l = list(map(int,input().split()))

min_prices = l[0]#初始化最小值
dp = [0]*n       #每一个位置的最大价值
dp[0] = 0        #初始化dp表(这一步可以不用)
for i in range(1,n):
    if l[i]>min_prices:
        #更新dp
        dp[i] = l[i]-min_prices
    else:
        #更新最小值
        min_prices = l[i]
print(max(dp))