import sys

readline = sys.stdin.readline

n = int(eval(input()))

min_r = int(eval(input()))

max_r = -1e10

for _ in range(n - 1):

    r = int(readline())

    max_r = max(max_r, r - min_r)

    min_r = min(min_r, r)

print(max_r)



import sys

readline = sys.stdin.readline

n = int(eval(input()))

min_r = int(eval(input()))

max_r = -1e10

for _ in range(n - 1):

    r = int(readline())

    if max_r < r - min_r:

        max_r = r - min_r

    if min_r > r:

        min_r = r

print(max_r)



import sys

readline = sys.stdin.readline
n = int(eval(input()))
min_r = int(eval(input()))
max_r = -1e10
for _ in range(n - 1):
    r = int(readline())
    max_r = max(max_r, r - min_r)
    min_r = min(min_r, r)
print(max_r)

import sys

readline = sys.stdin.readline
n = int(eval(input()))
min_r = int(eval(input()))
max_r = -1e10
for _ in range(n - 1):
    r = int(readline())
    if max_r < r - min_r:
        max_r = r - min_r
    if min_r > r:
        min_r = r
print(max_r)

-    max_r = max(max_r, r - min_r) -    min_r = min(min_r, r) +    if max_r < r - min_r: +        max_r = r - min_r +    if min_r > r: +        min_r = r