i=input

r=range

N=int(i())

A=[int(i()) for _ in r(N)]

mp=A[1]-A[0]

mn=A[0]

for a in r(1,N):

    x=A[a]

    b=x-mn

    if mp<(b):

        mp=b

        if 0>b:mn=x

    if x<mn:mn=x

print(mp)
import sys

i=input

n = int(i())

r0 = int(i())

r1 = int(i())

mx = r1-r0

mn = min(r1,r0)

for i in map(int,sys.stdin.readlines()):

    a=i-mn

    if mx<a:

        mx=a

        if 0>a:mn=i

    elif mn>i:mn=i

print(mx)
i = input
r = range
N = int(i())
A = [int(i()) for _ in r(N)]
mp = A[1] - A[0]
mn = A[0]
for a in r(1, N):
    x = A[a]
    b = x - mn
    if mp < (b):
        mp = b
        if 0 > b:
            mn = x
    if x < mn:
        mn = x
print(mp)

import sys

i = input
n = int(i())
r0 = int(i())
r1 = int(i())
mx = r1 - r0
mn = min(r1, r0)
for i in map(int, sys.stdin.readlines()):
    a = i - mn
    if mx < a:
        mx = a
        if 0 > a:
            mn = i
    elif mn > i:
        mn = i
print(mx)

+import sys + -r = range -N = int(i()) -A = [int(i()) for _ in r(N)] -mp = A[1] - A[0] -mn = A[0] -for a in r(1, N): -    x = A[a] -    b = x - mn -    if mp < (b): -        mp = b -        if 0 > b: -            mn = x -    if x < mn: -        mn = x -print(mp) +n = int(i()) +r0 = int(i()) +r1 = int(i()) +mx = r1 - r0 +mn = min(r1, r0) +for i in map(int, sys.stdin.readlines()): +    a = i - mn +    if mx < a: +        mx = a +        if 0 > a: +            mn = i +    elif mn > i: +        mn = i +print(mx)