n = int(input())



R = [0 for i in range(n)]



ans = 1 - 10**9

min_R = int(input())

for i in range(n-1):

    R[i] = int(input())

    if R[i] - min_R > ans:

        ans = R[i] - min_R

    if R[i] < min_R:

        min_R = R[i]

        

print(ans)

    

    

    
import sys



n = int(input())



min_R = int(input())

nums = list(map(int, sys.stdin.readlines()))



ans = -10**9



for num in nums:

    if num - min_R > ans:

        ans = num - min_R

    if num < min_R:

        min_R = num

        

print(ans)
n = int(input())
R = [0 for i in range(n)]
ans = 1 - 10**9
min_R = int(input())
for i in range(n - 1):
    R[i] = int(input())
    if R[i] - min_R > ans:
        ans = R[i] - min_R
    if R[i] < min_R:
        min_R = R[i]
print(ans)

import sys

n = int(input())
min_R = int(input())
nums = list(map(int, sys.stdin.readlines()))
ans = -(10**9)
for num in nums:
    if num - min_R > ans:
        ans = num - min_R
    if num < min_R:
        min_R = num
print(ans)

+import sys + -R = [0 for i in range(n)] -ans = 1 - 10**9 -for i in range(n - 1): -    R[i] = int(input()) -    if R[i] - min_R > ans: -        ans = R[i] - min_R -    if R[i] < min_R: -        min_R = R[i] +nums = list(map(int, sys.stdin.readlines())) +ans = -(10**9) +for num in nums: +    if num - min_R > ans: +        ans = num - min_R +    if num < min_R: +        min_R = num