import math
A = []
N = int(input())
maxdiff = 0
for n in range(N):
    A.append(int(input()))
R = tuple(A)

Dmax = R[1] -R[0]
Rmin = R[0]

for i in range(1, N):
    if R[i] >= R[i-1]:
        if R[i] - Rmin > Dmax:
            Dmax = R[i] -Rmin
    if R[i] < Rmin:
        Rmin = R[i]
#    print(R[i], Dmax, Rmin)

print(Dmax) import math math A = [] A [] N = int(input()) N int(input()) int input() input maxdiff = 0 maxdiff 0 for n in range(N):
    A.append(int(input())) n range(N) range N A.append(int(input())) A.append A append int(input()) int input() input R = tuple(A) R tuple(A) tuple A Dmax = R[1] -R[0] Dmax R[1] -R[0] R[1] R 1 R[0] R 0 Rmin = R[0] Rmin R[0] R 0 for i in range(1, N):
    if R[i] >= R[i-1]:
        if R[i] - Rmin > Dmax:
            Dmax = R[i] -Rmin
    if R[i] < Rmin:
        Rmin = R[i]
#    print(R[i], Dmax, Rmin) i range(1, N) range 1 N if R[i] >= R[i-1]:
        if R[i] - Rmin > Dmax:
            Dmax = R[i] -Rmin
     R[i] >= R[i-1] R[i] R i R[i-1] R i-1 i 1 if R[i] - Rmin > Dmax:
            Dmax = R[i] -Rmin
     R[i] - Rmin > Dmax R[i] - Rmin R[i] R i Rmin Dmax Dmax = R[i] -Rmin Dmax R[i] -Rmin R[i] R i Rmin if R[i] < Rmin:
        Rmin = R[i]
#    print(R[i], Dmax, Rmin) R[i] < Rmin R[i] R i Rmin Rmin = R[i] Rmin R[i] R i print(Dmax) print Dmax Rmin = R[i] R[i] Rmin R = tuple(A) tuple(A) R A = [] [] A Dmax = R[1] -R[0] R[1] -R[0] Dmax maxdiff = 0 0 maxdiff Rmin = R[0] R[0] Rmin N = int(input()) int(input()) N Dmax = R[i] -Rmin R[i] -Rmin Dmax
import math
A = []
N = int(input())
maxdiff = 0
for n in range(N):
    A.append(int(input()))
R = tuple(A)

Dmax = R[1] -R[0]
Rmin = R[0]

for i in range(1, N):
    if R[i] >= R[i-1]:
        if R[i] - Rmin > Dmax:
            Dmax = R[i] -Rmin
    if R[i] < Rmin:
        Rmin = R[i]
#    print(R[i], Dmax, Rmin)

print(Dmax)