def maximumProfit(A, N):
    minR = A[0]
    minP = A[1] - A[0]
    for i in range(1, N):
        R = A[i] - minR
        if R > minP:
            minP = R
        if A[i] < minR:
            minR = A[i]
    return minP

if __name__ == "__main__":
    N = input()
    A = []
    for i in range(N):
        A.append(input())
    print maximumProfit(A, N) def maximumProfit(A, N):
    minR = A[0]
    minP = A[1] - A[0]
    for i in range(1, N):
        R = A[i] - minR
        if R > minP:
            minP = R
        if A[i] < minR:
            minR = A[i]
    return minP maximumProfit minR = A[0] minR A[0] A 0 minP = A[1] - A[0] minP A[1] - A[0] A[1] A 1 A[0] A 0 for i in range(1, N):
        R = A[i] - minR
        if R > minP:
            minP = R
        if A[i] < minR:
            minR = A[i]
     i range(1, N) range 1 N R = A[i] - minR R A[i] - minR A[i] A i minR if R > minP:
            minP = R
         R > minP R minP minP = R minP R if A[i] < minR:
            minR = A[i]
     A[i] < minR A[i] A i minR minR = A[i] minR A[i] A i return minP minP A A N N if __name__ == "__main__":
    N = input()
    A = []
    for i in range(N):
        A.append(input())
    print maximumProfit(A, N) __name__ == "__main__" __name__ "__main__" N = input() N input() input A = [] A [] for i in range(N):
        A.append(input())
     i range(N) range N A.append(input()) A.append A append input() input print maximumProfit(A, N) maximumProfit A N A = [] [] A def maximumProfit(A, N):
    minR = A[0]
    minP = A[1] - A[0]
    for i in range(1, N):
        R = A[i] - minR
        if R > minP:
            minP = R
        if A[i] < minR:
            minR = A[i]
    return minP def maximumProfit(A, N):
    minR = A[0]
    minP = A[1] - A[0]
    for i in range(1, N):
        R = A[i] - minR
        if R > minP:
            minP = R
        if A[i] < minR:
            minR = A[i]
    return minP maximumProfit N = input() input() N
def maximumProfit(A, N):
    minR = A[0]
    minP = A[1] - A[0]
    for i in range(1, N):
        R = A[i] - minR
        if R > minP:
            minP = R
        if A[i] < minR:
            minR = A[i]
    return minP

if __name__ == "__main__":
    N = input()
    A = []
    for i in range(N):
        A.append(input())
    print maximumProfit(A, N)