n = eval(input())

maxv = - 1 * pow(10, 9)

minv = eval(input())

for _ in range(1, n):

    Rj = eval(input())

    maxv = max(maxv, Rj - minv)

    minv = min(minv, Rj)



print(maxv)
import sys



n = eval(input())

minv = eval(input())

maxv = - 1000000000

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

for num in nums:

    maxv = num - minv if num - minv > maxv else maxv

    minv = num if num < minv else minv



print(maxv)
n = eval(input())
maxv = -1 * pow(10, 9)
minv = eval(input())
for _ in range(1, n):
    Rj = eval(input())
    maxv = max(maxv, Rj - minv)
    minv = min(minv, Rj)
print(maxv)

import sys

n = eval(input())
minv = eval(input())
maxv = -1000000000
nums = list(map(int, sys.stdin.readlines()))
for num in nums:
    maxv = num - minv if num - minv > maxv else maxv
    minv = num if num < minv else minv
print(maxv)

+import sys + -maxv = -1 * pow(10, 9) -for _ in range(1, n): -    Rj = eval(input()) -    maxv = max(maxv, Rj - minv) -    minv = min(minv, Rj) +maxv = -1000000000 +nums = list(map(int, sys.stdin.readlines())) +for num in nums: +    maxv = num - minv if num - minv > maxv else maxv +    minv = num if num < minv else minv