def maximum_profit():
    n = int(input())
    numbers = [int(input()) for _ in range(n)]
    maxpro = numbers[1] - numbers[0]
    minnum = numbers[0]
    for i in range(1, len(numbers)):
        if maxpro < (numbers[i] - minnum):
            maxpro = (numbers[i] - minnum)
        if numbers[i] < minnum:
            minnum = numbers[i]
    print(maxpro)


if __name__ == "__main__":
    maximum_profit() def maximum_profit():
    n = int(input())
    numbers = [int(input()) for _ in range(n)]
    maxpro = numbers[1] - numbers[0]
    minnum = numbers[0]
    for i in range(1, len(numbers)):
        if maxpro < (numbers[i] - minnum):
            maxpro = (numbers[i] - minnum)
        if numbers[i] < minnum:
            minnum = numbers[i]
    print(maxpro) maximum_profit n = int(input()) n int(input()) int input() input int(input()) for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) int(input()) int input() input numbers = [int(input()) for _ in range(n)] numbers [int(input()) for _ in range(n)] maxpro = numbers[1] - numbers[0] maxpro numbers[1] - numbers[0] numbers[1] numbers 1 numbers[0] numbers 0 minnum = numbers[0] minnum numbers[0] numbers 0 for i in range(1, len(numbers)):
        if maxpro < (numbers[i] - minnum):
            maxpro = (numbers[i] - minnum)
        if numbers[i] < minnum:
            minnum = numbers[i]
     i range(1, len(numbers)) range 1 len(numbers) len numbers if maxpro < (numbers[i] - minnum):
            maxpro = (numbers[i] - minnum)
         maxpro < (numbers[i] - minnum) maxpro numbers[i] - minnum numbers[i] numbers i minnum maxpro = (numbers[i] - minnum) maxpro numbers[i] - minnum numbers[i] numbers i minnum if numbers[i] < minnum:
            minnum = numbers[i]
     numbers[i] < minnum numbers[i] numbers i minnum minnum = numbers[i] minnum numbers[i] numbers i print(maxpro) print maxpro if __name__ == "__main__":
    maximum_profit() __name__ == "__main__" __name__ "__main__" maximum_profit() maximum_profit def maximum_profit():
    n = int(input())
    numbers = [int(input()) for _ in range(n)]
    maxpro = numbers[1] - numbers[0]
    minnum = numbers[0]
    for i in range(1, len(numbers)):
        if maxpro < (numbers[i] - minnum):
            maxpro = (numbers[i] - minnum)
        if numbers[i] < minnum:
            minnum = numbers[i]
    print(maxpro) def maximum_profit():
    n = int(input())
    numbers = [int(input()) for _ in range(n)]
    maxpro = numbers[1] - numbers[0]
    minnum = numbers[0]
    for i in range(1, len(numbers)):
        if maxpro < (numbers[i] - minnum):
            maxpro = (numbers[i] - minnum)
        if numbers[i] < minnum:
            minnum = numbers[i]
    print(maxpro) maximum_profit
def maximum_profit():
    n = int(input())
    numbers = [int(input()) for _ in range(n)]
    maxpro = numbers[1] - numbers[0]
    minnum = numbers[0]
    for i in range(1, len(numbers)):
        if maxpro < (numbers[i] - minnum):
            maxpro = (numbers[i] - minnum)
        if numbers[i] < minnum:
            minnum = numbers[i]
    print(maxpro)


if __name__ == "__main__":
    maximum_profit()