#coding:UTF-8

def MP(n,a):
    minv=a[0]
    maxv=a[1]-a[0]
    for i in range(1,n):
        if maxv<a[i]-minv:
            maxv=a[i]-minv
        if minv>a[i]:
            minv=a[i]    
    print(maxv)
if __name__=="__main__":
    n=int(input())
    a=[]
    for i in range(n):
        a.append(int(input()))
    MP(n,a) def MP(n,a):
    minv=a[0]
    maxv=a[1]-a[0]
    for i in range(1,n):
        if maxv<a[i]-minv:
            maxv=a[i]-minv
        if minv>a[i]:
            minv=a[i]    
    print(maxv) MP minv=a[0] minv a[0] a 0 maxv=a[1]-a[0] maxv a[1]-a[0] a[1] a 1 a[0] a 0 for i in range(1,n):
        if maxv<a[i]-minv:
            maxv=a[i]-minv
        if minv>a[i]:
            minv=a[i]    
     i range(1,n) range 1 n if maxv<a[i]-minv:
            maxv=a[i]-minv
         maxv<a[i]-minv maxv a[i]-minv a[i] a i minv maxv=a[i]-minv maxv a[i]-minv a[i] a i minv if minv>a[i]:
            minv=a[i]    
     minv>a[i] minv a[i] a i minv=a[i] minv a[i] a i print(maxv) print maxv n n a a if __name__=="__main__":
    n=int(input())
    a=[]
    for i in range(n):
        a.append(int(input()))
    MP(n,a) __name__=="__main__" __name__ "__main__" n=int(input()) n int(input()) int input() input a=[] a [] for i in range(n):
        a.append(int(input()))
     i range(n) range n a.append(int(input())) a.append a append int(input()) int input() input MP(n,a) MP n a n=int(input()) int(input()) n a=[] [] a def MP(n,a):
    minv=a[0]
    maxv=a[1]-a[0]
    for i in range(1,n):
        if maxv<a[i]-minv:
            maxv=a[i]-minv
        if minv>a[i]:
            minv=a[i]    
    print(maxv) def MP(n,a):
    minv=a[0]
    maxv=a[1]-a[0]
    for i in range(1,n):
        if maxv<a[i]-minv:
            maxv=a[i]-minv
        if minv>a[i]:
            minv=a[i]    
    print(maxv) MP
#coding:UTF-8

def MP(n,a):
    minv=a[0]
    maxv=a[1]-a[0]
    for i in range(1,n):
        if maxv<a[i]-minv:
            maxv=a[i]-minv
        if minv>a[i]:
            minv=a[i]    
    print(maxv)
if __name__=="__main__":
    n=int(input())
    a=[]
    for i in range(n):
        a.append(int(input()))
    MP(n,a)