N = int(input())
A = list(map(int, input().split()))
A.reverse()
step = 0
ans = 0
for i in range(N):
    for j in range(i, N):
        if A[i] - A[j] > 0:
            step = A[i] - A[j]
            ans = max(ans, step)
print(ans)